How to mock the window size changing for a React component test with JavaScript?

To mock the window size changing for a React component test with JavaScript, we can mock the window.screen.width property.

For instance, we write

jest.spyOn(window.screen, "width", "get").mockReturnValue(1000);

to call jest.spyOn to mock the window.screen.width getter property.

And we call mockReturnValue to set its return value to 1000.