代码拆分`import`打破了Jest测试 [英] Code splitting `import` breaks Jest tests
本文介绍了代码拆分`import`打破了Jest测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用webpack的代码拆分功能,但似乎开玩笑无法识别import()
函数:
I'm using the code splitting feature of webpack, but it seems that jest doesn't recognize the import()
function:
import('myModule').then(function (myModule) {
^^^^^^
SyntaxError: Unexpected token import
我没有任何特殊设置.我的npm测试脚本只是运行jest "test": "jest"
I don't have any special setup. My npm test script is simply run jest "test": "jest"
我如何使它工作?
我正在使用最新版本的jest 20.0.4和babel-jest 20.0.3
I'm using the latest version of jest 20.0.4 and babel-jest 20.0.3
推荐答案
哦,我刚刚找到了答案.
Oh I just found the answer.
只需安装此插件: https://github.com/airbnb/babel -plugin-dynamic-import-node 并将其添加到.babelrc
文件:
Simply install this plugin: https://github.com/airbnb/babel-plugin-dynamic-import-node and add it to the .babelrc
file:
{
...
"env": {
"test": {
"plugins": ["dynamic-import-node"]
}
}
}
这篇关于代码拆分`import`打破了Jest测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文