Registry / testing / window-resizeto

window-resizeto

JSON →
library0.0.2jsnpmunverified

The `window-resizeto` package provides a polyfill and ponyfill for the `window.resizeTo` method, specifically designed for JavaScript test environments such as Jest and JSDOM. It addresses the common limitation in these environments where `window.resizeTo` is not natively implemented, leading to failures in tests that depend on window resizing functionality. The current stable version is 0.0.2, indicating it's still in early development, though seemingly stable for its intended purpose. Its release cadence appears infrequent, driven by specific fixes or minor enhancements. Key differentiators include its small footprint (under 10 lines of code) and its dual approach, offering both a global polyfill (`window-resizeto/polyfill`) and an explicit ponyfill function (`resizeTo`) for greater control. It effectively simulates window resizing by manipulating `outerWidth`, `outerHeight`, `innerWidth`, and `innerHeight` properties and dispatching a `resize` event, making it a drop-in solution for testing responsive UIs or logic tied to window dimensions without needing a full browser environment.

npm install window-resizeto
INSTALL
IMPORT
SIG · WINDOW-RESIZETO
W
window-resizeto
testingjavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

polyfill
import 'window-resizeto/polyfill'
const polyfill = require('window-resizeto/polyfill')
Used to apply the `window.resizeTo` polyfill globally as a side effect. Primarily for Jest's `setupFilesAfterEnv` or direct script imports.
resizeTo
import { resizeTo } from 'window-resizeto'
const { resizeTo } = require('window-resizeto')
Imports the `resizeTo` function for direct use as a ponyfill, allowing explicit control over which window object to resize, typically in environments where global polyfilling is not desired.
WindowWithResizeTo
import type { WindowWithResizeTo } from 'window-resizeto'
import { WindowWithResizeTo } from 'window-resizeto'
TypeScript type definition for a window object augmented with the `resizeTo` method. Use with `import type` to avoid bundling unused code.

Demonstrates how to integrate `window-resizeto` with Jest by adding the polyfill to `setupFilesAfterEnv`, enabling `window.resizeTo` in tests to simulate different screen sizes and test responsive UI logic.

// jest.config.js module.exports = { setupFilesAfterEnv: [ 'window-resizeto/polyfill' // Apply the window.resizeTo polyfill globally ] }; // tests/my-component.test.ts import '@testing-library/jest-dom'; // Example common import for test setup describe('Component with responsive behavior', () => { beforeEach(() => { // Reset window size for consistent tests window.resizeTo(1024, 768); }); test('should render correctly on mobile sizes', () => { window.resizeTo(375, 667); // Simulate mobile viewport // Assert on elements visible/hidden at mobile size expect(window.innerWidth).toBe(375); expect(window.innerHeight).toBe(667); }); test('should render correctly on desktop sizes', () => { window.resizeTo(1440, 900); // Simulate desktop viewport // Assert on elements visible/hidden at desktop size expect(window.innerWidth).toBe(1440); expect(window.innerHeight).toBe(900); }); });
Debug
Known issues
gotchaThe package name `window-resizeto` must be consistently used in lowercase. Older references or manual paths might have used `window-resizeTo` (with a capital 'T'), which could lead to import resolution issues, especially on case-sensitive file systems or in build environments.
fix
Ensure all imports, package.json dependencies, and file paths use the exact lowercase package name `window-resizeto`. Update any references with incorrect casing.
affects: >=0.0.1
Errors
Common errors & fixes
window.resizeTo is not a function
The `window-resizeto` polyfill has not been correctly applied or imported in the test environment, typically JSDOM.
fix
For Jest, add `'window-resizeto/polyfill'` to the `setupFilesAfterEnv` array in your `jest.config.js`. For standalone usage, ensure `import 'window-resizeto/polyfill'` is at the top of your test file or setup script before `window.resizeTo` is called.
Cannot find module 'window-resizeTo/polyfill'
Incorrect casing for the package name or import path. The official package name is `window-resizeto` (all lowercase).
fix
Correct the import path to `window-resizeto/polyfill` (ensure 'resizeto' is entirely lowercase).
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Resources
window-resizeto — npm install window-resizeto · libregistry