I'll start by saying that I am a javascript and dojo noob. However, I have been working on writing some unit tests for my js code, using the D.O.H framework. One thing I noticed is that the framework does not seem to have a way to mock XHR requests. So I decided to use sinon for the mocking.
Heres my question, I cannot successfully load the sinon code into my dojo module. Here is what I tried:
define(["doh/runner", "tests/sinon-1.4.2"], function(doh, sinnon) {
...
});
I have the tests package mapped to the correct directory, and can load other files from there. So how do I go about loading sinon?
A module in RequireJS is a scoped object and is not available in the global namespace. Hence, global namespace will not be polluted. RequireJS syntax allows to load modules faster without worrying about keeping track of the order of dependencies. You can load multiple versions of the same module in the same page.
Dojo was among the first JavaScript libraries to define a module API and publish a loader and build application to solve all of these problems. The original API included the functions dojo. require (request a module), dojo. provide (define a module), and other supporting functions.
Load it via Generic Script Injection:
require([
"doh/runner",
"http://sinonjs.org/releases/sinon-1.4.2.js"
], function(
doh
) {
console.log(doh);
console.log(sinon);
});
A working example at jsFiddle: http://jsfiddle.net/phusick/6tHtj/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With