GithubHelp home page GithubHelp logo

agilgur5 / window-resizeto Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 0.0 297 KB

A window.resizeTo polyfill for test environments like Jest & JSDOM (in <10 LoC)

License: Other

JavaScript 12.13% TypeScript 87.87%
window resizeto resize polyfill ponyfill jsdom jest test testing

window-resizeto's Introduction

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!

window-resizeto's People

Contributors

agilgur5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.