【发布时间】:2016-04-07 03:45:33
【问题描述】:
我有文件 foo.js:
export function bar (m) {
console.log(m);
}
还有另一个使用 foo.js 的文件 cap.js:
import { bar } from 'foo';
export default m => {
// Some logic that I need to test
bar(m);
}
我有 test.js:
import cap from 'cap'
describe('cap', () => {
it('should bar', () => {
cap('some');
});
});
不知何故,我需要在测试中覆盖 bar(m) 的实现。有没有办法做到这一点?
附:我使用 babel、webpack 和 mocha。
【问题讨论】:
-
您需要在哪里覆盖上限或测试?
-
在测试中,实际上我需要这个来将 cap 功能与 bar 隔离开来进行测试。
-
你用的是什么版本的 babel?
-
@DavinTryon 6.3.15,如果重要的话,我实际上可以使用任何。
-
如果你使用 babel 5,你可以使用这个插件:github.com/speedskater/babel-plugin-rewire。但它还不支持 babel 6。