Originally published in https://muhajirframe.com/writing/unit-test-typescript-jest/
In this article we'll try to cover a simple unit testing in ...
For further actions, you may consider blocking this person and/or reporting abuse
Just wanted to say that it may not work right away.
For example, in VSCode doing
Ctrl+Shift+P
>TypeScript: Restart TS server
helps, as sometimes it fails to recognizejest
, or the test file to be a module, etc.Also, for me, with this guide, I've had my VSCode failing to recognize
test
andexpect
functions in*.ts
files, showing errors, even though it worked overall withnpm run test
, passing these 2 tests.What helped me is to remove test files (here:
"**/*.spec.ts"
) from"exclude"
prop intsconfig.json
. Why would you do that in the first place? :)Nice article. I found it helpful, btw, in the article you say
npm run jest
but the script is called test.
Ah, nice find @ivorcummings . Now updated
I'm trying to follow your example but I get an
Unexpected token {
error then tring to impoet isInternalLink from main.spec.tsHere's a question at SO: stackoverflow.com/questions/578390...
and the public repo with the example: gitlab.com/opensas/jest-typescript
What am I doing wrong?
Sorry, my fault, I used jest.config.ts instead of jest.config.js... great tutorial!
Thanks for this article so I currently looking for good guide of jest integration with typescript for my library! Thanks!
No problem. Have a good a day :)
Nice post thanks! While following along, I had to add this to
tsconfig.json
to get it to work (after installing @types/jest):Otherwise, I'd get:
jest.config.js is not shown in the file tree. Also, it would be nice if you explain what is the significance of various config files and their params.
Clap for you Muhajir. Nice clean article.
Thanks bro
Awesome dude, u saved my time. TQ for posting.