Skip to content

Instantly share code, notes, and snippets.

@jeffmo
Last active August 29, 2015 14:01
Show Gist options
  • Save jeffmo/e154a997c5fb74780576 to your computer and use it in GitHub Desktop.
Save jeffmo/e154a997c5fb74780576 to your computer and use it in GitHub Desktop.
// __tests__/Foo-test.js
describe('hai', function() {
it('asdf', function() {
var mockedImplWithReturn = jest.genMockFn().mockImpl(function() {
console.log(' running impl');
return 'impl value';
}).mockReturnValue('mock return value');
var mockedImplWithoutReturn = jest.genMockFn().mockImpl(function() {
console.log(' running impl');
return 'impl value';
});
var ret;
console.log('Running mockedImplWithReturn:');
ret = mockedImplWithReturn();
console.log(' Returned:', ret);
console.log('Running mockedImplWithoutReturn:');
ret = mockedImplWithoutReturn();
console.log(' Returned:', ret);
});
});
Found 1 matching tests...
PASS __tests__/foo-test.js (0.011s)
Running mockedImplWithReturn:
Returned: mock return value
Running mockedImplWithoutReturn:
running impl
Returned: impl value
1 tests passed (1 total)
Run time: 1.075s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment