[英]Jest, Babel and Storybook, export vs module.exports
I am using Jest to test my services and Storybook and Babel to develop my React components.我使用 Jest 来测试我的服务,使用 Storybook 和 Babel 来开发我的 React 组件。
I have a service which my component needs to use.我有我的组件需要使用的服务。 I currently export with
module.exports = someFunction;
我目前使用
module.exports = someFunction;
导出module.exports = someFunction;
and it passes my Jest unit tests, but storybook tells me Cannot assign to read only property 'exports' of object '#<Object>'
in the browser console.它通过了我的 Jest 单元测试,但故事书告诉我
Cannot assign to read only property 'exports' of object '#<Object>'
浏览器控制台Cannot assign to read only property 'exports' of object '#<Object>'
。
If I change the service to export default someFunction
, the component works but the Jest unit test fails with SyntaxError: Unexpected token export
.如果我将服务更改为
export default someFunction
,则该组件可以工作,但 Jest 单元测试失败并显示SyntaxError: Unexpected token export
。
What do I do to make both work?我该怎么做才能使两者都起作用?
Notes:笔记:
module.exports
or export
.module.exports
或export
。 I have no real preference at this time.module.exports
.module.exports
的问题。 Would a downgrade help?Solved by adding a file called babel.config.js
with the contents:通过添加一个名为
babel.config.js
的文件来解决:
module.exports = {
presets: ['@babel/env']
};
If anyone has a better answer or believes they can educate me in the numerous areas I'm sure I'm shortcoming, they are welcome to do so.如果有人有更好的答案或相信他们可以在我确信我有缺点的众多领域对我进行教育,欢迎他们这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.