如何使用 ES6 模块模拟单元测试的依赖项 [英] How to mock dependencies for unit tests with ES6 Modules

查看:29
本文介绍了如何使用 ES6 模块模拟单元测试的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 webpack + traceur 来处理 Ecmascript 6 模块以转换为 ES5 CommonJS,但我无法成功地对它们进行单元测试.

I'm trying to fiddle with Ecmascript 6 modules using webpack + traceur to transpile to ES5 CommonJS, but I'm having trouble successfully unit testing them.

我尝试使用 Jest + traceur 预处理器,但是 automocking 和依赖项名称似乎变得很奇怪,而且我似乎无法让 sourceMaps 与 Jest 和 node-inspector 调试一起使用.

I tried using Jest + traceur preprocessor, but the automocking and dependency names seem to get screwy, plus I can't seem to get sourceMaps to work with Jest and node-inspector debugging.

是否有更好的框架来对 ES6 模块进行单元测试?

Is there a better framework to unit test ES6 modules?

推荐答案

我实际上是通过放弃 Jest 并使用 Karma + Jasmine + Webpack 并使用 https://github.com/jhnns/rewire 来模拟依赖

I actually got this to work by dropping Jest and going with Karma + Jasmine + Webpack and using https://github.com/jhnns/rewire to mock dependencies

这篇关于如何使用 ES6 模块模拟单元测试的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆