Jest 中的四个钩子函数
(一) beforeAll
在所有单元测试之前触发,参数是回调函数
(二) afterAll
在所有单元测试之后触发,参数是回调函数
(三) beforeEach
在每一个测试之前都会执行,参数是回调函数
(四) afterEach
在每一个测试之后都会执行,参数是回调函数
import { getIndex } from '../code/index'
beforeAll(() => {
console.log('unit test is beginning')
})
beforeEach(() => {
console.log('each start')
})
test('获取异步', () => {
expect(getIndex('h', 'hello')).toEqual(0)
})
afterEach(() => {
console.log('each end')
})
afterAll(() => {
console.log('unit test end')
})