
Recently, I have been learning to write some tests in React using Jest and RTL(React Testing Library), which has been a fun and eye-opening adventu...
For further actions, you may consider blocking this person and/or reporting abuse
Thank for the article! Guys if you're getting an error:
"Cannot use JSX unless the '--jsx' flag is provided" then I hope this might help you(worked for me):
I am using Vite + React + TypeScript + Jest. I deleted tsconfig.app.json (comes out of the box) and tsconfig.node.json. So it's only tsconfig.json(code below). And it solved my problem with imports and jsx.
Thank you Sergey! This saved me.
I made a couple changes on top of yours in order to keep the
tsconfig.json | tsconfig.app.json | tsconfig.node.json
configuration intact.Modified
jest.config.ts
to this:Then moved your
compilerOptions
from above into a new file namedtsconfig.test.json
.Cheers!
Great post, it's definitely not straightforward to setup unit testing for a React + Vite project. I recently wrote a similar article on this as well; it covers how to setup vitest, RTL, Husky, ESLint & Prettier.
Thanks Rajae. Will definitely checkout your article.
I get this error when i try to run tests :(
don't know how to fix this, i've already tried everything :/
try to remove offensive words should help!
@s1ckgit, а ты это здорово придумал с label, жалко никто не оценил! Ставлю кла$$ за оригинальность :)
I have fixed my issue by adding and pinning the versions of jest-environment and jest-config to the same version as jest.
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
no fluffs and straight to the point, cheers mate!
This was really helpful for me. Thanks!
Thank you, it's working. I got ts error, but after adding "esModuleInterop": true in tsconfig.json it went away.
Thanks! this was a huge time saver
I am happy you found it useful Isaac. :)
it is really good! Saved a lot of time. Thank you so much
Thank you very much! This article helped me a lot.