我尝试过这个解决方案,但效果不好。
以下是上面链接中的示例代码:
require([
"doh/runner",
"http://sinonjs.org/releases/sinon-1.17.5.js"
], function(doh){
console.log(sinon);
});
错误消息:
$ node ../../dojo/dojo.js load=doh test=tests/test_sinon_spy.js
Error: ENOENT: no such file or directory, open 'http://sinonjs.org/releases/sinon-1.17.5.js'
除此之外,我还尝试直接要求sinon.js。
sinon-1.17.5.js
已移动到与runner.js
相同的目录doh
,并重命名为sinon
。(目录(
require([
"doh/runner",
"doh/sinon"
], function(doh, sinon){
console.log(sinon);
});
没有错误消息,但sinon未定义:
$ node ../../dojo/dojo.js load=doh test=tests/test_sinon_spy.js
undefined
0 'tests to run in' 0 'groups'
------------------------------------------------------------
| TEST SUMMARY:
------------------------------------------------------------
0 tests in 0 groups
0 errors
0 failures
我确信第二个代码加载sinon很好。我通过直接修改sinon.js
来验证这一点。但我不知道西农为什么不能打电话。
版本
node.js - v6.2.2
dojo/doh - 1.10.0
sinon - 1.17.5
[更新]
因为node.js
和dojo
都有需要API,但它们不同。这种情况不起作用,因为它应该使用node.js的API来要求sinon.js
,而不是dojo的API。
Dojo提供Dojo/node模块,它将直接调用node.js模块。
1.通过npm在dojo的同一目录下安装sinon
$ cd ../../dojo
$ npm install sinon
2.修改代码以使用dojo/node
# test_sinon_spy.js
require([
"doh/runner",
"dojo/node!sinon"
], function(doh, sinon){
console.log(sinon);
})
3.返回原始文件夹并运行测试
$ cd -
$ node ../../dojo/dojo.js load=doh test=tests/test_sinon_spy.js
注意,在dojo目录下,它将包含npm_module/sinon