All Questions
101
questions
0
votes
0
answers
35
views
Unable to mock Webpack-defined global variables in Jest testing
I was trying to test a function using Jest where I need to mock a Webpack-defined global to test all the cases. I was unable to do so.
// webpack.config.js
...
new webpack.DefinePlugin({
__ENV__: `'${...
0
votes
1
answer
246
views
Stylex fails to compile during jest tests: "stylex.create should never be called. It should be compiled away."
Stylex compiles fine when I'm developing normally with webpack.
npm run start
But when I run my tests I get an error saying:
● Test suite failed to run
stylex.create should never be called. It ...
0
votes
0
answers
48
views
Jest cannot compile absolute imports in a React project
I'm using absolute imports in my project, but when I try to import a module, Jest is unable to compile it. I have tried adding the folder paths to the moduleNameMapper object, but this is not working. ...
0
votes
0
answers
59
views
The path alias are not recognised in the react.js app
I have a React.js app by Typescript. Instead of unpacking the Webpack, I use Craco for my alias and the app works fine. Now, I try to setup Jest but it doesn't recognize the alias, and fails on the ...
1
vote
0
answers
349
views
How to render Module Federation Component inside of my test DOM?
I'm writing Jest tests for a React.js application and using the React Testing Library. My application imports module federation components.
I need to find a way to test the app with these federated ...
0
votes
0
answers
37
views
change config-overrides.js location
Hello dear stackoverflow users. I have a react project. I have a config-overrides.js file that comes with react-app-rewired in this project, and Sonarqube analyzes this file even though it shouldn't, ...
1
vote
2
answers
608
views
Test Tailwind pruning in React app with Jest
Is there a way to test Tailwind's pruning with Jest, without having to write custom postcss configuration and only implement the default webpack config created by CRA 5 (also implemented here
).
...
0
votes
2
answers
524
views
SyntaxError: Unexpected token 'export' Babel Jest, React project
I have a problem with the unit tests of my React project, it is configured to be compiled with webpack, however when executing the unit tests they are giving me this error:
SyntaxError: Unexpected ...
0
votes
1
answer
245
views
Jest can't resolve module with parameter
When I try to run my Jest tests I'm getting this error:
Cannot find module 'core-js/modules/es.array.flat#?./my-file-path' from 'src/some-of-my-files.js'
Require stack:
> 1 | import "core-js/...
2
votes
1
answer
355
views
Environment key "jest/globals" is unknown - different behavior for CLI vs webpack-eslint-plugin
I’m running into this error:
Error: ../library/.eslintrc.js » ../app/.eslintrc.js » eslint-config-react-app/jest#overrides[0]:
Environment key "jest/globals" is unknown
at /home/...
12
votes
2
answers
18k
views
How to exclude test files in next.js during build?
I am creating next.js app with tests inside the page directory.
For this I have added config to next.config.js
const { i18n } = require('./next-i18next.config');
const nextConfig = {
...
1
vote
0
answers
538
views
Exclude coverage directory in React JS build
When I build my React JS application by running the react-scripts build script in package.json, I see that the build directory contains two sub-directories - coverage and static. As I have analyzed, ...
6
votes
1
answer
2k
views
How to test a lazy loaded components within the react router?
I need a way to test a component in which two other components are lazy loaded.
We are using webpack module federation. So here ComponentOne and ComponentTwo are micro-frontends that are lazy loaded ...
0
votes
1
answer
2k
views
React: Jest configuration Issue with Path Aliases
I have set up a React custom boilerplate and it uses Webpack 5, TypeScript and other libs. I am trying to set up Jest but I am getting an error when the test runs that Cannot find module 'utils/...
4
votes
2
answers
10k
views
Jest not finding alias path
I recently created an alias path to import my components so I can avoid importing components like this ../../../../componentFolder and instead do @src/componentFolder.
My issue is that my unit tests ...