4
我有一个Jest测试套件无法运行,因为它试图测试的组件取决于RequireJS模块。下面是我看到的错误:在Jest测试依赖于RequireJS的es6模块的“定义未定义”
FAIL __tests__/components/MyComponent.test.js
● Test suite failed to run
ReferenceError: define is not defined
at Object.<anonymous> (node_modules/private-npm-module/utils.js:1:90)
组件具有以下导入:
import utils from 'private-npm-module';
而且private-npm-module
设置像这样:
define('utils', [], function() {
return {};
});
当MyComponent
被transpiled与babel并在浏览器中运行,依赖关系正常运行。此问题仅影响单元测试。如何让我的测试套件在具有RequireJS依赖项的组件上运行?
我在package.json的jest config中使用babel-jest
作为我的scriptPreprocessor
。我正在使用jest v0.15.1。