mq-polyfill
CSSOM-valid and jsdom/Jest-compatible matchMedia polyfill for server-side unit tests.
Install
npm install --save-dev mq-polyfill
Usage
;; const window = defaultView; /** * Define the window.matchMedia */; window // Create MediaQueryList instance ; // Subscribe to MQ mode changes /** * For dispatching resize event * we must implement window.resizeTo in jsdom */window { Object;}; window;// console.log() output:// MediaQueryList { media: '(min-width: 920px)', matches: false } window;// Do nothing (MQ mode heven't changed) window;// console.log() output:// MediaQueryList { media: '(min-width: 920px)', matches: true }