August 2017
Beginner
374 pages
10h 41m
English
All mock functions have a special .mock property, which stores data about how the function has been called:
const getUser = jest.fn()getUser('dan')getUser('des')console.log(getUser.mock.calls)
The preceding example would print the following output:
[ ['dan'], ['des'] ]
The .mock property also keeps track of the value of this for each call:
const mockTest = jest.fn()const a = new mockTest()const b = {}const bound = mockTest.bind(b)bound()console.log(mockTest.mock.instances)
The preceding example would print an array with the context a and the context b, like this: [ <a>, <b> ].
Read now
Unlock full access