在Intern中调用Chai插件会返回错误 [英] Calling Chai plugin in Intern returns error

查看:55
本文介绍了在Intern中调用Chai插件会返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Intern中使用 sinon-chai插件,但它给了我:/p>

I was trying to use the sinon-chai plugin within Intern but it gave me:

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

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

I had installed the plugin via npm and here's my test file:

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_modules 的相对路径是 ../node_modules ):

The node loader requires Node.js, so it can't be used in the browser. You'll need to load the sinon-chai library directly, as shown below (assuming the relative path from your test to node_modules is ../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-chai软件包来简化测试,包括:

You could simplify the test include by defining a sinon-chai package in your intern config:

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

那么您就可以通过:

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

这篇关于在Intern中调用Chai插件会返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆