【发布时间】:2018-10-13 08:19:34
【问题描述】:
我花了很长时间查看有关此的其他问题并查看 Github 上的其他项目,但似乎没有一个答案对我有用。
我在我的项目中加载第三方库,运行 Jest 测试时出现错误
export default portalCommunication;
^^^^^^
SyntaxError: Unexpected token export
> 1 | import portalCommunication from 'mathletics-portal-communication-service';
我已尝试以多种方式更新我的 Jest 配置以使其转译此库,但我总是遇到相同的错误。
这是我当前的 jest.config.js 文件:
module.exports = {
moduleNameMapper: {
'\\.(css|scss)$': 'identity-obj-proxy',
'\\.svg$': '<rootDir>/test/mocks/svg-mock.js'
},
setupFiles: ['./test/test-setup.js'],
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!mathletics-portal-communication-service)'
]
};
我还尝试添加转换属性以针对这个 mathletics-portal-communication-service 目录运行 babel-jest。
请帮忙!
【问题讨论】:
-
你可能需要配置 babel。
-
我的项目设置了 babel 并且工作正常,我需要为 Jest 做些什么特别的事情吗?我以为它会自动使用 babel-jest?
标签: javascript reactjs jestjs babel-jest