我正在尝试使用Jest测试基本的反应组件,但是当我尝试导入组件时它会中断。编辑:注意到如果我加载一个更简单的组件它不会抛出此错误。我试图加载的那个基本相同,但有一个async
实例方法。也许那就是开玩笑?
test.js
import React from 'react';
import {shallow} from 'enzyme';
import Component from '../components/component';
describe('Component', () => {
it('renders the player component', () => {
expect(true).toBe(true)
});
});
.babelrc
{
"presets": ["es2015", "react"]
}
package.json jest config:
"jest": {
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json",
"jsx"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/react-dom",
"<rootDir>/node_modules/react-addons-test-utils"
]
}
答案 0 :(得分:2)
您可能正确地认为async
关键字打破了测试。如果您使用较低版本的NodeJS而不是v7.6运行此测试,则.babelrc
文件中使用的预设不支持async / await。
您需要其中一个预设/插件: