question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[react-jss] Jest tests error

See original GitHub issue

Problem with testing react with jest. I am getting this error whenever I use jss in a component.

Screenshot from 2020-09-23 17-41-26

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:open
  • Created 3 years ago
  • Reactions:10
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jasmaacommented, Jul 2, 2022

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 and node_modules/jss. Jest tries to use node_modules/react-jss/src/jss.js first instead of node_modules/jss which is causing the error. When I renamed node_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 the react-jss version I currently had. This added a nested node_modules within node_modules/react-jss which react-jss consumed jss from instead of from src.

1reaction
playfulpachydermcommented, Dec 5, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found