I am writing a react app and testing it with jest. However, whenever I run the jest
command from the terminal, I keep this error.
TypeError: projects.map is not a function
at Object.<anonymous> (/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:172:28)
at next (native)
at step (/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:18:30)
at /Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:34:14
at Object.<anonymous> (/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:15:12)
at Object.module.exports [as runCLI] (/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:2 03:17)
at Object.run (/Users/DavidHu/.nvm/versions/node/v6.2.1/lib/node_modules/jest-cli/build/cli/index.js:42:17)
at Object.<anonymous> (/Users/DavidHu/.nvm/versions/node/v6.2.1/lib/node_modules/jest-cli/bin/jest.js:16:25)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
I went into node_modules
to look at the line of code that is causing the error, projects
is a string of the project current path.
Here is my jest configuration in package.json
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}
Has anyone encountered this error and know how to fix it?
Just ran into the same problem. If you look at your stack trace closely you'll notice that you run two different Jest setups:
Globally installed jest:
...(/Users/DavidHu/.nvm/versions/node/v6.2.1/lib/node_modules/jest-cli/bin/jest.js:16:25)
Jest from the project:
...(/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:172:28)
They are probably have different (and incompatible) versions.
If you remove jest from your project (or from global node_modules
) that should solve the problem.
This will happen if you update jest in your project but run it using just jest
from the command line (not from node_modules).
To fix you'll need to update your global jest:
npm install -g jest
I had the same issue. I was passing a string to the 'projects' parameter instead of an array.
Wrapping the string 'projectPath' in [] fixed it for me (this is located inside a Gulp task):
var jestCLI = require('jest-cli');
...
jestCLI.runCLI({'onlyChanged': true}, [projectPath], callback);
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