Skip to content

Commit

Permalink
fix mock return value (#3933)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov authored and cpojer committed Jun 29, 2017
1 parent 30f35c3 commit eb9be5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/jest-mock/src/__tests__/jest_mock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ describe('moduleMocker', () => {
});
});

test('mockImplementation resets the mock', () => {
const fn = jest.fn();
expect(fn()).toBeUndefined();
fn.mockReturnValue('returnValue');
fn.mockImplementation(() => 'foo');
expect(fn()).toBe('foo');
});

it('should recognize a mocked function', () => {
const mockFn = moduleMocker.fn();

Expand Down
1 change: 1 addition & 0 deletions packages/jest-mock/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class ModuleMockerClass {
// next function call will use mock implementation return value
const mockConfig = this._ensureMockConfig(f);
mockConfig.isReturnValueLastSet = false;
mockConfig.defaultReturnValue = undefined;
mockConfig.mockImpl = fn;
return f;
};
Expand Down

0 comments on commit eb9be5a

Please sign in to comment.