当我在Jest中运行npm测试命令时,我得到以下错误意外关键字‘
’
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
SyntaxError: /Users/steinko/development/TutorialKubernetesClient/JestConfig/cluster.test.js: Unexpected keyword 'new'. (5:11)
3 |
4 | it('should exist a kubeconfig', {
> 5 | expect(new kubernetesClient.KubeConfig()).not.toBeNull();
| ^
6 | })
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:134:45)
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:129:17)
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:78:17)
at Parser.checkReservedWord (node_modules/@babel/parser/src/parser/expression.js:2386:12)
at Parser.parseIdentifierName (node_modules/@babel/parser/src/parser/expression.js:2336:12)
at Parser.parseIdentifier (node_modules/@babel/parser/src/parser/expression.js:2306:23)
at Parser.parseBindingAtom (node_modules/@babel/parser/src/parser/lval.js:299:17)
at Parser.parseMaybeDefault (node_modules/@babel/parser/src/parser/lval.js:370:25)
at Parser.parseAssignableListItem (node_modules/@babel/parser/src/parser/lval.js:346:23)
at Parser.parseBindingList (node_modules/@babel/parser/src/parser/lval.js:336:24)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
sum.js | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.069 s失败的测试如下所示
const kubernetesClient = require('@kubernetes/client-node');
it('should exist a kubeconfig', {
expect(new kubernetesClient.KubeConfig()).not.toBeNull();
})我已经通过以下方式设置了Jest环境:
npm install --save-dev jest生成基本配置文件。
jest --init具有以下配置的
将有助于Jest为您的项目创建合适的配置
✔ Would you like to use Typescript for the configuration file? … no
✔ Choose the test environment that will be used for testing › jsdom (browser-like)
✔ Do you want Jest to add coverage reports? … yes
✔ Which provider should be used to instrument code for coverage? › v8
✔ Automatically clear mock calls and instances between every test? … yes当我运行测试时,当我在测试中出错时,
PASS ./sum.test.js
FAIL ./cluster.test.js
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
SyntaxError: /Users/steinko/development/TutorialKubernetesClient/JestConfig/cluster.test.js: Unexpected keyword 'new'. (5:11)
3 |
4 | it('should exist a kubeconfig', {
> 5 | expect(new kubernetesClient.KubeConfig()).not.toBeNull();
| ^
6 | })
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:134:45)
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:129:17)
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:78:17)
at Parser.checkReservedWord (node_modules/@babel/parser/src/parser/expression.js:2386:12)
at Parser.parseIdentifierName (node_modules/@babel/parser/src/parser/expression.js:2336:12)
at Parser.parseIdentifier (node_modules/@babel/parser/src/parser/expression.js:2306:23)
at Parser.parseBindingAtom (node_modules/@babel/parser/src/parser/lval.js:299:17)
at Parser.parseMaybeDefault (node_modules/@babel/parser/src/parser/lval.js:370:25)
at Parser.parseAssignableListItem (node_modules/@babel/parser/src/parser/lval.js:346:23)
at Parser.parseBindingList (node_modules/@babel/parser/src/parser/lval.js:336:24)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
sum.js | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.069 s,我要做什么才能修复这个错误?
发布于 2021-07-09 13:22:09
it('should exist a kubeconfig', {应该是
it('should exist a kubeconfig', function() {https://stackoverflow.com/questions/68317442
复制相似问题