August 2017
Beginner
374 pages
10h 41m
English
Mock functions can also mock return values. For example, let's say we want to mock the result of a getPosts function:
const getPosts = jest.fn()getPosts.mockReturnValueOnce([ { title: 'test' } ])console.log(getPosts())// output: [ { title: 'test' } ]console.log(getPosts())// output: undefined
If we want to return the same value every time, we need to use a mock implementation.
Read now
Unlock full access