Want to test a Jest console.log? If you want to check that console.log received the right parameter (the one that you passed in) you should check mock of your jest.fn().
You also have to invoke your log function, otherwise console.log
is never invoked:
1 2 3 4 5 6 | it('console.log the text "hello"', () => { console.log = jest.fn(); log('hello'); // The first argument of the first call to the function was 'hello' expect(console.log.mock.calls[0][0]).toBe('hello'); }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.