这是我的模块和测试我想要的功能:摩卡嘲讽进口变量
import aVariable from 'aModule'
export function afunction() {
//do something with the imported aVariable
//calculates result
return result
});
我想嘲笑aVariable我摩卡单元测试。
import {afunction} from 'aModule.js'
describe('Tests',() => {
it('should return expected',() => {
expect(afunction()).to.equal(expected);
});
这可能吗?
UPDATE:
使用的巴别塔,联控,插件我.babelrc:
{
"env": {
"dev": {
"presets": ["es2015"]
},
"test": {
"plugins": ["rewire"]
}
}
}
当我运行我的测试:
meteor test --meteortesting:mocha
我得到这个错误:
TypeError: _getServiceUrl(...).__Rewire__ is not a function
当我使用:
BABEL_ENV=test meteor test --meteortesting:mocha
我得到:
While processing files with ecmascript (for target web.browser):
/node_modules/rewire/lib/rewire.js:19:15: Filename must be a string
你看过[重新连接](https://www.npmjs.com/package/babel-plugin-rewire)babel的插件?它可以让你轻松做到这样的事情。另外还有[另一个rewire library](https://www.npmjs.com/package/rewire),如果你不使用babel,你可以使用它。 – robbymurphy
我已经看到rewire,但我并没有意识到你可以使用我和我的样机进口,并使用Babel作为一个转译器。 – Gobliins