window-resizeto
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

window-resizeto

package-json releases commits
dt dy dm dw
typings build status code coverage
NPM
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.js
    module.exports = {
      setupFilesAfterEnv: [
        // polyfill window.resizeTo
        'window-resizeto/polyfill'
      ]
    }
    // some-test.spec.js
    window.resizeTo(500, 500)
    // window is now resize to 500x500
  • Standalone with the polyfill:

    import 'window-resizeto/polyfill'
     
    window.resizeTo(500, 500)
    // window is now resized to 500x500
  • With the ponyfill:

    import { resizeTo } from 'window-resizeto'
     
    resizeTo(window, 500, 500)
    // 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!

Package Sidebar

Install

npm i window-resizeto

Weekly Downloads

2,798

Version

0.0.2

License

Apache-2.0

Unpacked Size

14.4 kB

Total Files

23

Last publish

Collaborators

  • agilgur5