当前位置:网站首页>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();
});
边栏推荐
猜你喜欢
随机推荐
语言模型(NNLM)
Policy Evaluation收敛性、炼丹与数学家
FP6293电池升压5V-12V大电流2APWM模式升压方案
Binder机制(中篇)
define #使用
LLVM系列第六章:函数返回值Return
基于无监督医学图像配准论文(1)
Publish module to NPM should be how to operate?Solutions to problems and mistake
2.4G无线小模块CI24R1超低成本
STL容器自定义内存分配器
PyTorch②---transforms结构及用法
FP7126降压恒流65536级高辉无频闪调光共阳极舞台灯RGB驱动方案
基于GPT的隐变量表征解码结构
【我的电赛日记(二)】ADF4351锁相环模块
Win11没有本地用户和组怎么解决
CI24R1小模块2.4G收发模块无线通信低成本兼容si24r1/XN297超低功耗
PyTorch①---加载数据、tensorboard的使用
LLVM系列第九章:控制流语句if-else
How to add a one-key shutdown option to the right-click menu in Windows 11
PyTorch⑦---卷积神经网络_非线性激活









