Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Jest from running tests on TS files and only on JS files

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?

like image 257
hyper_text_coffee_pot Avatar asked Nov 22 '25 14:11

hyper_text_coffee_pot


1 Answers

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".

like image 154
hyper_text_coffee_pot Avatar answered Nov 24 '25 03:11

hyper_text_coffee_pot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!