Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在Intern中调用Chai插件返回错误_Node.js_Dojo_Requirejs_Intern - Fatal编程技术网

Node.js 在Intern中调用Chai插件返回错误

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,

我试图使用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, 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) {
...
});