console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Not implemented: window.scrollTo at module.exports (/Users/me/Projects/my-project/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17) at /Users/me/Projects/my-project/node_modules/jsdom/lib/jsdom/browser/Window.js:594:7 Because we are using window.scrollTo(0,0).
Also getting Not implemented Navigation for:
window.location.replace(externa_link) same error happens with .assign.
I tried googling for solutions with react-router, but all examples use some component which contains window.location.
Is there a way to avoid this error? Or hide it?
I did some research and found that the Facebook team isn't going to address it. Is there a way to suppress these errors/warnings when running jest test?
Our code doesn't break and all tests pass otherwise.
Try running the jest command with --env=jsdom. This will mock most browser functions and will solve your issues.
There are more ways of setting the test environment, take a look at:
https://jestjs.io/docs/en/configuration#testenvironment-string
This worked for the window.scrollTo errors
https://qiita.com/akameco/items/0edfdae02507204b24c8
At the top of the test file after the imports mock it like this :
window.scrollTo = jest.fn(); Then inside the describe add this:
afterAll(() => { jest.clearAllMocks(); }); so if you are also reseting all mocks after each you will end up with this ::
afterEach(() => { jest.resetAllMocks(); }); afterAll(() => { jest.clearAllMocks(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With