osm-spline / xappy.js

Xappy.JS
Other
37 stars 4 forks source link

injector loop #92

Closed lusy closed 13 years ago

lusy commented 13 years ago

if you export your modules in the injector and at the same time call it in them it sometimes comes to a injector loop, where functions complain to be undefined

mren commented 13 years ago

i do not see any reason to use the injector, can somebody tell me what the advantage is?

if the reason to use the injector is to unit test modules like http we can achieve this with easier options. For example

var HTTP = require('http');

function XappiFactory() {
   return Foo(HTTP);
}

function Foo(http) {
    // normal code
}

Another option is to use our testing framework http://sinonjs.org/docs/#sinonspy

{
    setUp: function () {
        sinon.spy(jQuery, "ajax");
    },

    tearDown: function () {
        jQuery.ajax.restore(); // Unwraps the spy
    },

    "test should inspect jQuery.getJSON's usage of jQuery.ajax": function () {
        jQuery.getJSON("/some/resource");

        assert(jQuery.ajax.calledOnce);
        assertEquals("/some/resource", jQuery.ajax.getCall(0).args[0].url);
        assertEquals("json", jQuery.ajax.getCall(0).args[0].dataType);
    }
}
lusy commented 13 years ago

we took the injector completely out