Open BenParr64 opened 1 year ago
include this in your test-setup.js
/**
* fix: `matchMedia` not present, legacy browsers require a polyfill
*/
global.matchMedia = global.matchMedia || function() {
return {
matches: false,
addListener: function() { },
removeListener: function() { }
}
}
Hi @BenParr64 , I'm currently facing similar issue. Have you been able to resolve it, or are you still experiencing the issue?
If you found a solution or any workarounds, I would appreciate it if you could share your insights.
Hey mate, I think I just mocked it but I can try and find the code and get back to you! Cheers
Sent from Samsung Mobile on O2 Sent from Outlook for Androidhttps://aka.ms/AAb9ysg
From: saikiranravupalli @.> Sent: Thursday, May 25, 2023 6:22:42 AM To: akiran/react-slick @.> Cc: Ben Parr @.>; Mention @.> Subject: Re: [akiran/react-slick] Issue with Jest (Issue #2202)
Hi @BenParr64https://github.com/BenParr64 , I'm currently facing similar issue. Have you been able to resolve it, or are you still experiencing the issue?
If you found a solution or any workarounds, I would appreciate it if you could share your insights.
— Reply to this email directly, view it on GitHubhttps://github.com/akiran/react-slick/issues/2202#issuecomment-1562288470, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASYAXNNNKG5LSJJ6RNOZ5ZDXH3UCFANCNFSM6AAAAAATAAHQBE. You are receiving this because you were mentioned.Message ID: @.***>
@saikiranravupalli You should also be able to fix it by adding this code near the top of the file containing your tests, before the tests are run:
Object.defineProperty(window, 'matchMedia', {
value: () => {
return {
matches: false,
addListener: () => {},
removeListener: () => {}
};
}
})
Issue occuring when trying to write jest tests
I have followed the docs and added the following to setupTests.json
I am still getting the following error:
matchMedia not present, legacy browsers require a polyfill
Package Json:
I cannot add a
test-setup.js
as there is already ajest.config.ts
in the project. Is there a fix for this?Cheers