{"id":14354,"library":"window-resizeto","title":"Window ResizeTo Polyfill for Test Environments","description":"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.","status":"active","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/agilgur5/window-resizeto","tags":["javascript","window","resizeTo","resize","polyfill","ponyfill","jsdom","jest","test","typescript"],"install":[{"cmd":"npm install window-resizeto","lang":"bash","label":"npm"},{"cmd":"yarn add window-resizeto","lang":"bash","label":"yarn"},{"cmd":"pnpm add window-resizeto","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Used to apply the `window.resizeTo` polyfill globally as a side effect. Primarily for Jest's `setupFilesAfterEnv` or direct script imports.","wrong":"const polyfill = require('window-resizeto/polyfill')","symbol":"polyfill","correct":"import 'window-resizeto/polyfill'"},{"note":"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.","wrong":"const { resizeTo } = require('window-resizeto')","symbol":"resizeTo","correct":"import { resizeTo } from 'window-resizeto'"},{"note":"TypeScript type definition for a window object augmented with the `resizeTo` method. Use with `import type` to avoid bundling unused code.","wrong":"import { WindowWithResizeTo } from 'window-resizeto'","symbol":"WindowWithResizeTo","correct":"import type { WindowWithResizeTo } from 'window-resizeto'"}],"quickstart":{"code":"// jest.config.js\nmodule.exports = {\n  setupFilesAfterEnv: [\n    'window-resizeto/polyfill' // Apply the window.resizeTo polyfill globally\n  ]\n};\n\n// tests/my-component.test.ts\nimport '@testing-library/jest-dom'; // Example common import for test setup\n\ndescribe('Component with responsive behavior', () => {\n  beforeEach(() => {\n    // Reset window size for consistent tests\n    window.resizeTo(1024, 768);\n  });\n\n  test('should render correctly on mobile sizes', () => {\n    window.resizeTo(375, 667); // Simulate mobile viewport\n    // Assert on elements visible/hidden at mobile size\n    expect(window.innerWidth).toBe(375);\n    expect(window.innerHeight).toBe(667);\n  });\n\n  test('should render correctly on desktop sizes', () => {\n    window.resizeTo(1440, 900); // Simulate desktop viewport\n    // Assert on elements visible/hidden at desktop size\n    expect(window.innerWidth).toBe(1440);\n    expect(window.innerHeight).toBe(900);\n  });\n});","lang":"typescript","description":"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."},"warnings":[{"fix":"Ensure all imports, package.json dependencies, and file paths use the exact lowercase package name `window-resizeto`. Update any references with incorrect casing.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"search_vec":"'/polyfill':112 '0.0.2':62 '10':96 'address':33 'appear':80 'approach':103 'browser':161 'cadenc':79 'code':99 'common':35 'control':121 'current':58 'depend':52 'design':22 'develop':69 'differenti':90 'dimens':156 'dispatch':136 'driven':82 'drop':144 'drop-in':143 'dual':102 'earli':68 'effect':123 'enhanc':88 'environ':6,26,39,162 'event':139 'explicit':115 'failur':48 'fix':85 'footprint':94 'full':160 'function':56,117 'global':107 'greater':120 'implement':45 'includ':91 'indic':63 'infrequ':81 'innerheight':133 'innerwidth':131 'intend':75 'javascript':24,163 'jest':29,170 'jsdom':31,169 'key':89 'lead':46 'limit':36 'line':97 'logic':152 'make':140 'manipul':128 'method':20 'minor':87 'nativ':44 'need':158 'offer':104 'outerheight':130 'outerwidth':129 'packag':11 'polyfil':3,14,108,167 'ponyfil':16,116,168 'properti':134 'provid':12 'purpos':76 'releas':78 'resiz':55,126,138,166 'resizeto':2,10,111,118,165 'respons':149 'seem':71 'simul':124 'small':93 'solut':146 'specif':21,84 'stabl':59,72 'still':66 'test':5,25,50,148,171 'though':70 'tie':153 'typescript':172 'ui':150 'version':60 'window':1,9,54,110,125,155,164 'window-resizeto':8,109 'window.resizeto':19,41 'without':157","created_at":"2026-04-20T01:59:16.369033+00:00","updated_at":"2026-04-20T01:59:16.369033+00:00","problems":[{"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.","cause":"The `window-resizeto` polyfill has not been correctly applied or imported in the test environment, typically JSDOM.","error":"window.resizeTo is not a function"},{"fix":"Correct the import path to `window-resizeto/polyfill` (ensure 'resizeto' is entirely lowercase).","cause":"Incorrect casing for the package name or import path. The official package name is `window-resizeto` (all lowercase).","error":"Cannot find module 'window-resizeTo/polyfill'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/agilgur5/window-resizeto","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/window-resizeto","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}