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

痴心易碎 提交于 2019-12-22 06:09:11

问题


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?


回答1:


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/



来源:https://stackoverflow.com/questions/12313624/how-to-load-a-js-file-that-is-not-a-module-in-dojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!