React-slick: With Chai Test: Adding react-slick throws error - matchMedia not present

Created on 20 Feb 2017  路  2Comments  路  Source: akiran/react-slick

After adding the react-slick slider to my webpack project, my chai test began to fail with
C:\project\projjs\node_modules\enquire.js\dist\enquire.js:226
throw new Error('matchMedia not present, legacy browsers require a polyfill');
^
Error: matchMedia not present, legacy browsers require a polyfill
at Object.MediaQueryDispatch (C:\project\projjs\node_modules\enquire.js\dist\enquire.js:226:19)
at C:\project\projjs\node_modules\enquire.js\dist\enquire.js:291:9
at i (C:\project\projjs\node_modules\enquire.js\dist\enquire.js:11:20)
at Object. (C:\project\projjs\node_modules\enquire.js\dist\enquire.js:21:2)

The only fix for this problem that the author of the slider component recommended here is for jest. I have tried that in my environment but it did not work.

http://stackoverflow.com/questions/42346998/with-chai-test-adding-react-slick-throws-error-matchmedia-not-present

Most helpful comment

@steelow It fixed for me adding this on my mocha setup:

global.window.matchMedia = window.matchMedia || (() => ({}));
global.matchMedia = global.window.matchMedia;

All 2 comments

I ended up throwing this react-slick slider into the garbage and creating my own slider instead. The react-slick slider is useless if only because unlike most npm packages out there, it managed to entangled itself with some arcane dependency. Perhaps platform specific requirement which the creator failed to communicate to prospective users. Completely useless unless you intend to test with jest.

@steelow It fixed for me adding this on my mocha setup:

global.window.matchMedia = window.matchMedia || (() => ({}));
global.matchMedia = global.window.matchMedia;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

artemidas picture artemidas  路  4Comments

nicreichert picture nicreichert  路  3Comments

ramyatrouny picture ramyatrouny  路  3Comments

briziel picture briziel  路  3Comments

walker-jiang picture walker-jiang  路  3Comments