jest
2019-07-17 11:43:37 0 举报
AI智能生成
一张图快速了解jest API
作者其他创作
大纲/内容
测试方法
测试异步代码
callback
Promises
returun a promise to jest
.resolves / .rejects
Async/Await
only async/await
with .resolves / .rejects
Mock Functions
created
const someMockFunction = jest.fn();
.mock property
执行次数
someMockFunction.mock.calls.length
参数
第一次执行的第一个参数someMockFunction.mock.calls[0][0]
instances
someMockFunction.mock.instances.length
someMockFunction.mock.instances[0].name
Mock Return Values
mockReturnValueOnce
mockReturnValue
Mock Implementations
jest.fn
mockImplementation
mockImplementationOnce
Mock Names(快速定位用)
Custom Matchers
toBeCalled()
toBeCalledWith(arg1, arg2)
lastCalledWith(arg1, arg2)
toMatchSnapshot()
Configuring Jest
Matchers
commom
toEqual()
匹配对象
toBe()
boolean,number
Truthiness
toBeNull()
toBeFalsy()
toBeTruthy()
toBeDefined()
toBeUndefined()
Numbers
toBeGreaterThan()
toBeGreaterThanOrEqual()
toBeLessThan()
toBeLessThanOrEqual()
Strings
toMatch(reg)
Arrays
toContain()
Exceptions
toThrow(reg/string)
测试切面
方法
beforeEach
afterEach
beforeAll
afterAll
tips
Scoping
Order
link
https://github.com/sapegin/jest-cheat-sheet
0 条评论
下一页