August 2017
Beginner
374 pages
10h 41m
English
By default, the before and after functions apply to every test in a file. However, Jest also provides a way to group tests, via describe:
let posts = []beforeAll(() => { posts.push({ title: 'test', user: 'dan' }) posts.push({ title: 'hello world', user: 'dan' })})test('test post exists', () => expect(posts).toContain({ title: 'test' }))describe('resolving users for posts', () => { let users = [] beforeAll(() => { users.push({ username: 'dan', realname: 'Daniel Bugl' }) }) test('getting realname of author', () => expect(getAuthorRealname(posts[0])).toMatch('Daniel Bugl') )})
In the preceding example, the second beforeAll function only gets called for the tests in the describe block.
Read now
Unlock full access