window-resizeto
A window.resizeTo
polyfill for test environments like Jest & JSDOM.
Installation
npm i -D window-resizeto
Usage
There are a few different ways you can use window-resizeto
:
-
With Jest:
// jest.config.jsmoduleexports =setupFilesAfterEnv:// polyfill window.resizeTo'window-resizeto/polyfill'// some-test.spec.jswindow// window is now resize to 500x500 -
Standalone with the polyfill:
window// window is now resized to 500x500 -
With the ponyfill:
// window is now resized to 500x500
How it works
Basically just sets the window
's outerWidth
, outerHeight
, innerWidth
, innerHeight
, and fires a resize
event.
The source code is currently just <10 LoC, so take a look under the hood! :)
Credits
Inspiration for creating this came from mq-polyfill
and a few other code samples that are nearly exact replicas.
I wanted a package I could re-use in my projects' tests instead of having to constantly create a helper file, and so window-resizeto
was born!