Kir Chou
Kir Chou

Reputation: 3080

doh of dojo is not working with sinon

I have tried this solution, it not works well.

Here is the example code from the link above:

require([
    "doh/runner",
    "http://sinonjs.org/releases/sinon-1.17.5.js"
], function(doh){
    console.log(sinon);
});

Error message:

$ 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'

Besides this, I also try to require sinon.js directly.

sinon-1.17.5.js have been moved to the directory doh which is as same as runner.js, and renamed to sinon. (The directory )

require([
    "doh/runner",
    "doh/sinon"
], function(doh, sinon){
    console.log(sinon);
});

There is no error message, but sinon is undefined:

$ 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

I am pretty sure that the second code loads sinon well. I verified that by modifying sinon.js directly. But I have no idea why sinon is not able to call.


Version

node.js - v6.2.2
dojo/doh - 1.10.0
sinon - 1.17.5

Upvotes: 0

Views: 171

Answers (1)

Kir Chou
Kir Chou

Reputation: 3080

[UPDATED]

Because both node.js and dojo have require API, but they are different. This case is not working because it should use node.js's API to require sinon.js rather than dojo's API.

Dojo provide the dojo/node module, it will call node.js module directly.

1. Install sinon by npm under same directory of dojo

$ cd ../../dojo
$ npm install sinon

2. Modify the code to use dojo/node

# test_sinon_spy.js
require([
    "doh/runner",
    "dojo/node!sinon"
], function(doh, sinon){
    console.log(sinon);
})

3. Back to original folder and run the test

$ cd -
$ node ../../dojo/dojo.js load=doh test=tests/test_sinon_spy.js

Note, under dojo directory, it will contain npm_module/sinon

Upvotes: 0

Related Questions