August 2017
Beginner
374 pages
10h 41m
English
Sometimes you only need to carry out the setup once, before all your tests run. For this case, Jest provides beforeAll and afterAll functions. They work the same way as beforeEach and afterEach, but only run once for the whole test file:
let posts = []beforeAll(() => { posts.push({ title: 'test' }) posts.push({ title: 'hello world' })})test('test post exists', () => expect(posts).toContain({ title: 'test' }))test('hello world post exists', () => expect(posts).toContain({ title: 'hello world' }))
Read now
Unlock full access