Error: Not implemented: window.scrollTo. How do we remove this error from Jest test?

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

Update

This worked for the window.scrollTo errors

https://qiita.com/akameco/items/0edfdae02507204b24c8


In *.test.js file that calls a component that has window.scrollTo

it("renders without crashing", () => {
  window.scrollTo = jest.fn()
})

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();
  });