try this line:

window = object.assign(window, { innerwidth: 500 });


if you are getting the typescript error message

cannot assign to 'innerwidth' because it is a read-only property.


object.defineproperty(window, 'innerwidth', {writable: true, configurable: true, value: 200})


using jest and enzyme you can do the following. jest has jsdom baked in. in your tests jest provides the window object and it is represented by global (i think that the default window.innerwidth set by jest is 1024px):

test('test something when the viewport changes.', () => {

    // mount the component to test.
    const component = mount(<componenttotest/>);


    // change the viewport to 500px.
    global.innerwidth = 500;

    // trigger the window resize event.
    global.dispatchevent(new event('resize'));


    // run your assertion.

Related Query

More Query from same tag