Node.js 在Intern中调用Chai插件返回错误
我试图使用Internal实习生,但它给了我:Node.js 在Intern中调用Chai插件返回错误,node.js,dojo,requirejs,intern,Node.js,Dojo,Requirejs,Intern,我试图使用Internal实习生,但它给了我: 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,
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);
...
});
可能出现什么问题?节点加载器需要node.js,因此无法在浏览器中使用。您需要直接加载sinon chai库,如下所示(假设从测试到
节点\单元
的相对路径为。/node\单元
):
您可以通过在实习生配置中定义sinon chai软件包来简化测试:
...
loader: {
{ name: 'sinon-chai', location: 'node_modules/sinon-chai/lib' },
...
}
...
然后,您只需:
define([
...
'sinon-chai/sinon-chai'
], function (bed, expect, myapp, chai, sinonChai) {
...
});
你浏览过了吗?这就是我为实习设置集成
chai-spies
库的方法。需要注意的一点是,我必须在package.json中单独安装chai lib,并在测试文件中包含node_modules文件夹中的chai lib,以便使用chai.use()
方法
define([
...
'sinon-chai/sinon-chai'
], function (bed, expect, myapp, chai, sinonChai) {
...
});