Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a JS file that is not a module in dojo?

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?

like image 668
ekj Avatar asked Sep 07 '12 07:09

ekj


People also ask

What is module in require JS?

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.

What is Dojo loader?

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.


1 Answers

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/

like image 145
phusick Avatar answered Oct 01 '22 06:10

phusick