SyntaxError:运行Jest时,SPFx解决方案意外导出令牌



我收到这个错误:

FAIL  srcwebpartscrud__test__CrudWebPart.test.tsx
● Test suite failed to run
C:UsersadminDesktopgithubcrud-simple-testnode_modules@microsoftsp-httplibindex.js:12
export { default as HttpClient } from './httpClient/HttpClient';
^^^^^^
SyntaxError: Unexpected token export
54 | 
55 |     async postTodo() {
> 56 |         const value = await this.addItem(this.state.todo);
57 |         const action = postTodoCreator(value);
58 |         store.dispatch(action)
59 |     }
at ScriptTransformer._transformAndBuildScript (node_modules/jest/node_modules/jest-runtime/build/script_transformer.js:316:17)
at Object.<anonymous> (src/webparts/crud/components/Todolist/Todolist.tsx:56:68)
at Object.<anonymous> (src/webparts/crud/components/Crud.tsx:17:70)
console.log srcwebpartscrudcomponentsStorereducers.ts:27
action type @@redux/INITb.1.9.m.y.8 is not found
Handlebars: Access has been denied to resolve the property "statements" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "branches" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "functions" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "lines" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                   |
----------|----------|----------|----------|----------|-------------------|
Jest: Coverage data for global was not found.
Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        8.522s
Ran all test suites.
testResultsProcessor support is deprecated. Please use jest reporter. See https://github.com/jest-community/jest-junit#usage:
{
"reporters": [
"jest-junit"
]
}
npm ERR! Test failed.  See above for more details.

这很奇怪,因为在做了一些研究后,我更改了配置:

"transformIgnorePatterns": [
"/node_modules/(?!@microsoft/sp-core-library|sp-dialog|sp-http)"
],

然而,这个小小的解决方案似乎并没有解决问题,尽管人们似乎就是这样解决类似问题的。这是打字问题还是其他问题?我如何确保Typescript编译器完成它的工作?

在我的情况下,我配置了package.json,因此jest忽略了所有这些:

"transformIgnorePatterns": [ "node_modules/(?!(@microsoft/sp-dialog|@microsoft/office-ui-fabric-react-bundle|@microsoft/sp-diagnostics|@microsoft/sp-core-library|@microsoft/sp-http|@microsoft/sp-page-context|@microsoft/sp-dynamic-data|@pnp/sp|@pnp/common|@pnp/odata|@pnp))" ],

相关内容

最新更新