[react-jss] Jest tests error
See original GitHub issueProblem with testing react with jest. I am getting this error whenever I use jss in a component.
Also i have a valid config for jest:
{
"moduleDirectories": [
"node_modules",
"src"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|pdf)$": "identity-obj-proxy"
},
"preset": "ts-jest",
"roots": [
"<rootDir>/src"
],
"setupFilesAfterEnv": [
"<rootDir>/src/setupTests.js"
],
"testEnvironment": "jsdom",
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{ts,tsx}",
"<rootDir>/src/**/*(*.)(spec|test).{ts,tsx}",
"<rootDir>/test/**/*.{ts,tsx}",
"<rootDir>/test/**/?(*.)(spec|test).{ts,tsx}"
],
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "babel-jest"
},
"verbose": true
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Testing an error thrown by a React component using ...
I was able to suppress the console.log error by mocking it like so: const consoleErrorFn = jest.spyOn(console, 'error').mockImplementation(() => ...
Read more >How to make a Jest Test for Error Boundaries
Error boundaries are a nifty part of the React API to handle errors. Basically, an error that occurs within the error boundary propagates...
Read more >Successfully Throwing Async Errors with the Jest Testing ...
Below is a very, very simplified version of the React component I needed to unit test with Jest. I'll break down what its...
Read more >React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. Very happy about the upgrade. But I start to see test errors like this: In...
Read more >How to clear script errors in React Jest testing?
This article explains bow to clear the script error thrown while running Jest test for Syncfusion components using the “@testing-library/React” package.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to reproduce the error here. It looks like the issue is from a conflict between
node_modules/react-jss/src/jss.js
andnode_modules/jss
. Jest tries to usenode_modules/react-jss/src/jss.js
first instead ofnode_modules/jss
which is causing the error. When I renamednode_modules/react-jss/src/jss.js
to something else, the error went away.Only workaround I found is to create a version conflict by installing a version of
jss
different from thereact-jss
version I currently had. This added a nestednode_modules
withinnode_modules/react-jss
whichreact-jss
consumedjss
from instead of fromsrc
.I’m getting this problem too, and despite a lot of searching, I haven’t found any workarounds for it. It seems like until this is addressed I won’t be able to use JSS.