Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created December 28, 2019 18:17
Show Gist options
  • Select an option

  • Save r3dm1ke/1bf11b0c8281abd4790cbc10e8698c5a to your computer and use it in GitHub Desktop.

Select an option

Save r3dm1ke/1bf11b0c8281abd4790cbc10e8698c5a to your computer and use it in GitHub Desktop.
Spying on functions with Jest
export const do_stuff = () => {
console.error('Cannot do stuff!');
};
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