Javascript JEST配置测试节点_模块,即使其已禁用?
我正在使用Jest向现有代码库添加测试。这就是我得到的错误Javascript JEST配置测试节点_模块,即使其已禁用?,javascript,node.js,vue.js,jestjs,Javascript,Node.js,Vue.js,Jestjs,我正在使用Jest向现有代码库添加测试。这就是我得到的错误 Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. By default, if Jest sees a Babel config, it will use that
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• 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/en/configuration.html
Details:
/home/me/app/node_modules/register-service-worker/index.js:32
export function register (swUrl, hooks) {
^^^^^^
SyntaxError: Unexpected token export
我不明白如何正确配置transformIgnorePatterns
?
但是我的jest.config.js
设置为忽略节点模块
?
正在研究,但无法真正理解它如何转化为我的东西。。。?我在VueJS项目中,没有使用类型脚本
module.exports = {
preset: "@vue/cli-plugin-unit-jest/presets/typescript-and-babel",
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1",
},
transformIgnorePatterns: ["/node_modules/"],
// setupFiles: [
// "./tests/unit/setup.ts",
// ],
};
module.exports={
预设:“@vue/cli插件单元jest/presets/typescript和babel”,
模块映射:{
“^@/(.*)$”:“/src/$1”,
},
transformIgnorePatterns:[“/node_modules/”],
//设置文件:[
//“/tests/unit/setup.ts”,
// ],
};
似乎扩展了jest.config.js
解决了上述错误
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
},
“转换”:{
“*\ \(vue)$”:“/node\u模块/vue笑话”,
“^.+\.js$”:“/node\u modules/babel jest”
},
我现在有一个不同的错误,但现在这是更特定于Vue的错误。我的建议是,为
注册服务人员创建一个。无论如何,你不应该真正测试第三方代码。你见过@Phil吗?OP不是在测试第三方代码,他们想知道为什么node\u模块
没有被忽略。为该服务人员创建模拟只会导致node\u modules
中的其他内容尝试传输。@Adam我的意思是,测试中包含的第三方代码超出了您的控制范围。在国际海事组织,合作者应该controlled@Adam不幸的是,相关建议没有起到任何作用。同样的错误。我会试图嘲笑它,因为我需要知道,无论如何。。。但是如果有人知道如何阻止Jest查看我的节点模块
,请告诉我。谢谢:)