WickyNilliams / enquire.js

Awesome Media Queries in JavaScript
http://wicky.nillia.ms/enquire.js/
MIT License
3.63k stars 269 forks source link

Error: matchMedia not present, legacy browsers require a polyfill #169

Closed dschinkel closed 6 years ago

dschinkel commented 6 years ago

We're using react-slick which is using your enquire somewhere in its implementation.

When we run our own mocha tests in our project that's using react-slick we get Error: matchMedia not present, legacy browsers require a polyfill. But why should our project care anything about enquire.js?

This is what I get when running our tests

screen shot 2018-01-29 at 2 14 05 pm

I've tried adding this to my jsdom.js but no luck:

const jsdom = require('jsdom').jsdom;

global.document = jsdom('<!doctype html><html><body id=\'root\'></body></html>');
global.window = document.defaultView;

window.matchMedia || (
  window.matchMedia = function () {
    return {
      matches: false,
      addListener() {},
      removeListener() {},
  };
});

global.navigator = window.navigator;
dschinkel commented 6 years ago

just went with the usual for now, it resolves it, good enough to move on..the mock was working but I was referencing some other jsdom code I had elsewhere so didn't realize it.

window.matchMedia || (
  window.matchMedia = function () {
    return {
      matches: false,
      addListener() {},
      removeListener() {},
  };
});