akiran / akiran/react-slick

Issue with Jest

Open
#2,202 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
11.9k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

### Issue occuring when trying to write jest tests

I have followed the docs and added the following to setupTests.json

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

I am still getting the following error:

` matchMedia not present, legacy browsers require a polyfill
`

Package Json:
```
{
"name": "kegthat-headless",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "jest"
},
"dependencies": {
"@apollo/client": "^3.7.2",
"@types/node": "18.11.15",
"@types/react": "18.0.26",
"@types/react-dom": "18.0.9",
"axios": "^0.21.1",
"eslint": "8.29.0",
"eslint-config-next": "13.0.6",
"jest-environment-jsdom": "^29.3.1",
"lodash": "^4.17.21",
"next": "13.0.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-slick": "^0.29.0",
"slick-carousel": "^1.8.1",
"typescript": "4.9.4"
},
"devDependencies": {
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/react-slick": "^0.23.10",
"autoprefixer": "^10.4.13",
"babel-jest": "^29.3.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.3.1",
"jest-cli": "^29.3.1",
"polyfill": "^0.1.0",
"postcss": "^8.4.20",
"tailwindcss": "^3.2.4",
"ts-node": "^10.9.1"
}
}

```
I cannot add a `test-setup.js` as there is already a `jest.config.ts` in the project. Is there a fix for this?

Cheers

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.