我试图在实习生内部使用sinon-chai插件,但它给了我:
Error {stack: (...), message: "Cannot find the Node.js require"} 我已经通过npm安装了插件,下面是我的测试文件:
define([
'intern!bdd',
'intern/chai!expect',
'app/functions',
'intern/chai',
'intern/dojo/node!sinon-chai'
], function (bdd, expect, myapp, chai, sinonChai) {
chai.use(sinonChai);
...
});会出什么问题?
发布于 2014-09-23 19:49:38
节点加载程序需要Node.js,因此不能在浏览器中使用。您需要直接加载sinon库,如下所示(假设从测试到node_modules的相对路径是../node_modules):
define([
'intern!bdd',
'intern/chai!expect',
'app/functions',
'intern/chai',
'../node_modules/sinon-chai/lib/sinon-chai'
], function (bdd, expect, myapp, chai, sinonChai) {
chai.use(sinonChai);
...
});您可以通过在实习生配置中定义sinon包来简化测试包括:
...
loader: {
{ name: 'sinon-chai', location: 'node_modules/sinon-chai/lib' },
...
}
...然后你就可以过得很好了:
define([
...
'sinon-chai/sinon-chai'
], function (bed, expect, myapp, chai, sinonChai) {
...
});https://stackoverflow.com/questions/25995984
复制相似问题