admin管理员组文章数量:1401618
So i just started learning about Test Driven Developement and as an example i was asked to run the mand npm test helloWorld.spec.js
in the terminal but i got this error :
> [email protected] test
> jest "helloWorld.spec.js"
'jest' n’est pas reconnu en tant que mande interne
ou externe, un programme exécutable ou un fichier de mandes.
// in english jest isn't recognized as an internal mand or external
I'm working on windows and the only thing i have installed is node so what do i have to do?
So i just started learning about Test Driven Developement and as an example i was asked to run the mand npm test helloWorld.spec.js
in the terminal but i got this error :
> [email protected] test
> jest "helloWorld.spec.js"
'jest' n’est pas reconnu en tant que mande interne
ou externe, un programme exécutable ou un fichier de mandes.
// in english jest isn't recognized as an internal mand or external
I'm working on windows and the only thing i have installed is node so what do i have to do?
Share Improve this question asked Feb 14, 2022 at 21:42 Rafik BouloudeneRafik Bouloudene 6356 silver badges14 bronze badges 1-
Have you run
npm install
? Npm learns what to do when you runnpm test
frompackage.json
(thescripts
section). Also in thepackage.json
file are listed the project dependencies (Jest is one of them, it seems) andnpm install
installs the project dependencies. – axiac Commented Apr 11, 2023 at 7:32
2 Answers
Reset to default 5Choose one of the following methods
1) Install globally
You need to install jest
globally:
npm install jest -g
Note: You will have to call it as jest something.spec.js
in your cli or specify a test
mand in your package.json
.
2) Install locally
Install jest
locally with npm install jest -D
.
You can use a script
in your package.json
called test
which would be "test": "jest"
.
- If any of the above don't work, try reinstalling
jest
. - If it still doesn't work, try removing
node_modules
andnpm cache clean --force
andnpm install
3) Config file
If you already have jest
installed but it's not working, you can use a config file to track files based on regex pattern (you can do a lot more if you check out the docs).
The following part is from the docs:
Jest's configuration can be defined in the package.json
file of your project, or through a jest.config.js
, or jest.config.ts
file or through the --config <path/to/file.js|ts|cjs|mjs|json>
option. If you'd like to use your package.json
to store Jest's config, the "jest"
key should be used on the top level so Jest will know how to find your settings:
{
"name": "my-project",
"jest": {
"verbose": true
}
}
Or through JavaScript:
// Sync object
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
verbose: true,
};
module.exports = config;
// Or async function
module.exports = async () => {
return {
verbose: true,
};
};
Or through TypeScript (if ts-node
is installed):
import type {Config} from '@jest/types';
// Sync object
const config: Config.InitialOptions = {
verbose: true,
};
export default config;
// Or async function
export default async (): Promise<Config.InitialOptions> => {
return {
verbose: true,
};
};
When using the --config option, the JSON file must not contain a "jest" key:
{
"bail": 1,
"verbose": true
}
Regex options
testMatch
[array]
(default: [ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ])
The glob patterns Jest uses to detect test files. By default it looks for .js
, .jsx
, .ts
and .tsx
files inside of __tests__
folders, as well as any files with a suffix of .test
or .spec
(e.g. Component.test.js
or Component.spec.js
). It will also find files called test.js
or spec.js
.
Note: Each glob pattern is applied in the order they are specified in the config. (For example ["!**/__fixtures__/**", "**/__tests__/**/*.js"] will not exclude __fixtures__ because the negation is overwritten with the second pattern. In order to make the negated glob work in this example it has to e after **/__tests__/**/*.js.)
testRegex
[string | array]
Default: (/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$
The pattern or patterns Jest uses to detect test files. By default it looks for .js
, .jsx
, .ts
and .tsx
files inside of \_\_tests\_\_
folders, as well as any files with a suffix of .test
or .spec
(e.g. Component.test.js
or Component.spec.js
). It will also find files called test.js
or spec.js
. See also testMatch
[array], but note that you cannot specify both options.
you could add jest scripts on package.json
or else
you can use npx to access jest mands directly from the terminal i.e npx jest
本文标签: javascriptJest command not recognizedStack Overflow
版权声明:本文标题:javascript - Jest command not recognized - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744277276a2598474.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论