I am trying to run a test on a component at a certain viewport width. I am doing the following, but this doesn't seem to change it:
test('Component should do something at a certain viewport width.', () => {
global.innerWidth = 2000;
const component = mount(<SomeComponent />);
// ...
});
I also found an article that explains how to do it using JSDom, but as Jest now ships with JSDom, I wondered if there was a native solution.
https://www.codementor.io/pkodmad/dom-testing-react-application-jest-k4ll4f8sd
Background Information:
jsdomdoes not implementwindow.resizeBy()orwindow.resizeTo()jsdomdefines the window innerWidth and innerHeight to be 1024 x 768jsdomby manually setting window.innerWidth and window.innerHeight and firing theresizeeventHere is an example:
comp.js
comp.test.js
Notes:
Enzymev3shallowcalls React lifecycle methods likecomponentDidMount()so it can be used in place ofmount