在Intern中调用柴插件返回错误

我试图在实习生中使用sinon-chai插件 ,但它给了我:

Error {stack: (...), message: "Cannot find the Node.js require"} 

我已经通过npm安装了插件,这里是我的testing文件:

 define([ 'intern!bdd', 'intern/chai!expect', 'app/functions', 'intern/chai', 'intern/dojo/node!sinon-chai' ], function (bdd, expect, myapp, chai, sinonChai) { chai.use(sinonChai); ... }); 

什么可能会出错?

节点加载器需要Node.js,所以它不能在浏览器中使用。 您将需要直接加载sinon-chai库,如下所示(假设从testing到node_modules的相对path是../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); ... }); 

您可以通过在实习生configuration中定义一个sinon-chai包来简化testing:

 ... loader: { { name: 'sinon-chai', location: 'node_modules/sinon-chai/lib' }, ... } ... 

那么你可以通过只是:

 define([ ... 'sinon-chai/sinon-chai' ], function (bed, expect, myapp, chai, sinonChai) { ... });