当前位置:网站首页>jest test, component test
jest test, component test
2022-08-02 15:22:00 【N.S.N】
Jest Can help you achieve painless JavaScript 单元测试支持,由 Facebook 推出.
使用命令行 npx jest 文件进行测试
test('test common matcher', () => {
expect( 2 + 2 ).toBe(4)// 判断2+2是否等于4
expect( 2 + 3 ).not.toBe(4)
})
test('test to betrue or false', () => {
expect(1).toBeTruthy()//判断1是否为真
expect(0).toBeFalsy()
})
test('test number', () => {
expect(4).toBeGreaterThan(3) // 4是否比3大
expect(2).toBeLessThan(3) // 2是否比3小
})
test('test object', () => {
expect({
name: 'roadsign'}).toEqual({
name: 'roadsign'})
})
组件进行测试
Test cases must use the command linenpm test ,否则容易报错
import React from 'react';
import {
render } from '@testing-library/react';
import Button from './button';
test('our first react test case', () => {
const wrapper = render(<Button>nice</Button>);
const element = wrapper.queryByText('nice');
expect(element).toBeInTheDocument();
});
边栏推荐
猜你喜欢
镜像法求解接地导体空腔电势分布问题
PyTorch⑨---卷积神经网络_线性层
The problem that UIWindow's makeKeyAndVisible does not call viewDidLoad of rootviewController
PyTorch①---加载数据、tensorboard的使用
win10任务栏不合并图标如何设置
source /build/envsetup.sh和lunch)
Binder机制(中篇)
小T成长记-网络篇-1-什么是网络?
Win10 cannot directly use photo viewer to open the picture
Win11电脑一段时间不操作就断网怎么解决
随机推荐
FP6195耐压60V电流降压3.3V5V模块供电方案
PyTorch①---加载数据、tensorboard的使用
The problem that UIWindow's makeKeyAndVisible does not call viewDidLoad of rootviewController
win10 system update error code 0x80244022 how to do
Win7怎么干净启动?如何只加载基本服务启动Win7系统
“非图灵完备”到底意味着什么
FP7195大功率零压差全程无频闪调光DC-DC恒流芯片(兼容调光器:PWM调光,无极调光,0/1-10V调光)
将SSE指令转换为ARM NEON指令
FP5207电池升压 5V9V12V24V36V42V大功率方案
为android系统添加产品的过程
设备驱动框架简介
Win10系统设置application identity自动提示拒绝访问怎么办
Win10无法连接打印机怎么办?不能使用打印机的解决方法
刷卡芯片CI520可直接PIN对PIN替换CV520支持SPI通讯接口
最小树高度
小T成长记-网络篇-1-什么是网络?
神经网络可以解决一切问题吗:一场知乎辩论的整理
记录Yolo-tiny-v4的权重提取和中间层结果提取
PyTorch②---transforms结构及用法、常见的Transforms
Binder机制(下篇)