Created
December 28, 2019 18:17
-
-
Save r3dm1ke/1bf11b0c8281abd4790cbc10e8698c5a to your computer and use it in GitHub Desktop.
Spying on functions with Jest
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
| export const do_stuff = () => { | |
| console.error('Cannot do stuff!'); | |
| }; |
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
| import {do_stuff} from './main'; | |
| describe('doing stuff', () => { | |
| it('should do stuff', () => { | |
| const consoleErrorSpy = jest.spyOn(console, 'error'); | |
| do_stuff(); | |
| expect(consoleErrorSpy).toHaveBeenCalledTimes(0); // FAIL | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment