I can't get Jest, using the command npm test in my program to stop running tests on my TS files. I only want to run them on JS files.
PASS Views/Shared/Global.unit.test.js (14.83s)
FAIL Views/Shared/Global.unit.test.ts
I've got this in my package.json file:
{
"devDependencies": {
...,
"@types/jest": "^24.0.11",
"jest": "^24.7.1"
},
"scripts": {
"test": "jest"
}
}
I have written the tests in typescript and only want the tests to run the js. I've looked everywhere, but all I find are ways to add support for TS testing. I want it to only run on my .js files.
Anyone had this issue or know a fix?
After several hours of searching and messing with Jest documentation and settings, I finally found how to pick only the files you want Jest to look for. Add the "jest" field to the package.json file settings:
{
"devDependencies": {
...,
"@types/jest": "^24.0.11",
"jest": "^24.7.1"
},
"scripts": {
"test": "jest"
},
"jest": {
"testMatch": [
"**/?(*.)+(spec|test).[j]s?(x)"
]
}
}
This needs to be added to your package.json file. This is in the Jest Docs. In the regex above you need to change the .[jt]s just .[j]s, removing the "t".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With