You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test('object assignment',()=>{constdata={one: 1}data['two']=2expect(data).toEqual({one: 1,two: 2})})test('two plus two is four',()=>{expect(2+2).toBe(4)})
functioncompileCode(){thrownewError('you are using the wrong JDK');}test('function',()=>{expect(compileCode).toThrow();expect(compileCode).toThrow(Error);expect(compileCode).toThrow('you are using the wrong JDK');})
jest学习总结
最近要给项目添加单元测试,所以总结一下jest单元测试的语法点和单元测试的用意。
为什么要写单元测试
基本语法
相等判定
常见的false判定
常见的数字判定
字符串测试
数组
函数抛出错误
异步函数
callback
promises
expect.assertions(1)
assertions(1): 这里指的是断言必须只有一次,如果没有的话,就会报错,多余一次也会报错
Async/Await
安装和移除
beforeEach和afterEach
beforeAll和afterAll
describe作用域
The text was updated successfully, but these errors were encountered: