Last active
August 14, 2017 19:40
-
-
Save akameco/b3e805a8733ca7675c5e057ff6850464 to your computer and use it in GitHub Desktop.
mock console.log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
const sum = (a, b) => a + b | |
test('sum', () => { | |
expect(sum(1, 2)).toBe(3) | |
}) | |
const spyLog = jest.spyOn(console, 'log') | |
spyLog.mockImplementation(x => x) | |
const printSum = (a, b) => { | |
console.log(`sum = ${sum(a, b)}`) | |
} | |
test('printSum', () => { | |
printSum(1, 2) | |
expect(console.log).toBeCalled() | |
expect(spyLog.mock.calls[0][0]).toBe('sum = 3') | |
spyLog.mockReset() | |
spyLog.mockRestore() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment