I am trying to experiment some with the jest tester for react and when I do an npm test
, the test passes ok, but I get this error:
Snapshots: 0 total
console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Not implemented: window.alert
I know this is due to the fact that I an alert call in my code because if I comment that alert call out I don't get the error.
I tried the solution mentioned here but I still get the error. Is there any way I can eliminate this error while still keeping the alert call in my code?
Here's the test:
it('renders without crashing', () => {
jest.spyOn(window, 'alert').mockImplementation(() => {});
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});