Skip to content

Commit

Permalink
Support setting returnvalue from mock to undefined (#3354)
Browse files Browse the repository at this point in the history
Fixes #3320
  • Loading branch information
SimenB authored and cpojer committed Apr 25, 2017
1 parent fa018cc commit f465fb6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/jest-mock/src/__tests__/jest-mock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,26 @@ describe('moduleMocker', () => {
expect(fn2()).not.toEqual('abcd');
});
});

it('supports mock value returning undefined', () => {
const obj = {
func: () => 'some text',
};

moduleMocker.spyOn(obj, 'func').mockReturnValue(undefined);

expect(obj.func()).not.toEqual('some text');
});

it('supports mock value once returning undefined', () => {
const obj = {
func: () => 'some text',
};

moduleMocker.spyOn(obj, 'func').mockReturnValueOnce(undefined);

expect(obj.func()).not.toEqual('some text');
});
});

describe('getMockImplementation', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-mock/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ class ModuleMockerClass {
if (returnValue === undefined) {
returnValue = mockConfig.defaultReturnValue;
}

return returnValue;
}

// If mockImplementationOnce()/mockImplementation() is last set,
Expand Down

0 comments on commit f465fb6

Please sign in to comment.