@@ -41,13 +41,17 @@ expect(mockCallback.mock.calls[0][0]).toBe(0);
4141
4242// The first argument of the second call to the function was 1
4343expect (mockCallback .mock .calls [1 ][0 ]).toBe (1 );
44+
45+ // The return value of the first call to the function was 42
46+ expect (mockCallback .mock .returnValues [0 ]).toBe (42 );
4447```
4548
4649## ` .mock ` property
4750
4851All mock functions have this special ` .mock ` property, which is where data about
49- how the function has been called is kept. The ` .mock ` property also tracks the
50- value of ` this ` for each call, so it is possible to inspect this as well:
52+ how the function has been called and what the function returned is kept. The
53+ ` .mock ` property also tracks the value of ` this ` for each call, so it is
54+ possible to inspect this as well:
5155
5256``` javascript
5357const myMock = jest .fn ();
@@ -62,7 +66,7 @@ console.log(myMock.mock.instances);
6266```
6367
6468These mock members are very useful in tests to assert how these functions get
65- called, or instantiated :
69+ called, instantiated, or what they returned :
6670
6771``` javascript
6872// The function was called exactly once
@@ -74,6 +78,9 @@ expect(someMockFunction.mock.calls[0][0]).toBe('first arg');
7478// The second arg of the first call to the function was 'second arg'
7579expect (someMockFunction .mock .calls [0 ][1 ]).toBe (' second arg' );
7680
81+ // The return value of the first call to the function was 'return value'
82+ expect (someMockFunction .mock .returnValues [0 ]).toBe (' return value' );
83+
7784// This function was instantiated exactly twice
7885expect (someMockFunction .mock .instances .length ).toBe (2 );
7986
@@ -165,7 +172,7 @@ test('should fetch users', () => {
165172 const resp = {data: [{name: ' Bob' }]};
166173 axios .get .mockResolvedValue (resp);
167174
168- // or you could use the follwing depending on your use case:
175+ // or you could use the following depending on your use case:
169176 // axios.get.mockImpementation(() => Promise.resolve(resp))
170177
171178 return Users .all ().then (users => expect (users).toEqual (resp .data ));
0 commit comments