问题
I was trying to use the sinon-chai plugin within Intern but it gave me:
Error {stack: (...), message: "Cannot find the Node.js require"}
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);
...
});
What might go wrong?
回答1:
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);
...
});
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' },
...
}
...
Then you could get by with just:
define([
...
'sinon-chai/sinon-chai'
], function (bed, expect, myapp, chai, sinonChai) {
...
});
来源:https://stackoverflow.com/questions/25995984/calling-chai-plugin-in-intern-returns-error