Commit c5cd67a6 by valera-rozuvan Committed by Valera Rozuvan

Work on RequireJS Jasmine test.

parent f2cce07b
describe('RequireJS namespacing', function() { describe "RequireJS namespacing", ->
beforeEach(function() { beforeEach ->
this.addMatchers({ @addMatchers
requirejsTobeUndefined: function() { requirejsTobeUndefined: ->
return (typeof requirejs === 'undefined'); typeof requirejs is "undefined"
},
requireTobeUndefined: function() {
return (typeof require === 'undefined');
},
defineTobeUndefined: function() {
return (typeof define === 'undefined');
},
});
});
it('check that the RequireJS object is present in the global namespace', function() { requireTobeUndefined: ->
expect(RequireJS).toEqual(jasmine.any(Object)); typeof require is "undefined"
expect(window.RequireJS).toEqual(jasmine.any(Object));
});
it('check that requirejs(), require(), and define() are not in the global namespace', function () { defineTobeUndefined: ->
expect({}).requirejsTobeUndefined(); typeof define is "undefined"
expect({}).requireTobeUndefined();
expect({}).defineTobeUndefined();
expect(window.requirejs).not.toBeDefined();
expect(window.require).not.toBeDefined();
expect(window.define).not.toBeDefined();
});
});
describe('RequireJS module creation', function() { it "check that the RequireJS object is present in the global namespace", ->
var inDefineCallback, inRequireCallback; expect(RequireJS).toEqual jasmine.any(Object)
expect(window.RequireJS).toEqual jasmine.any(Object)
it('check that we can use RequireJS define() and require() a module', function() { it "check that requirejs(), require(), and define() are not in the global namespace", ->
runs(function () { expect({}).requirejsTobeUndefined()
inDefineCallback = false; expect({}).requireTobeUndefined()
inRequireCallback = false; expect({}).defineTobeUndefined()
expect(window.requirejs).not.toBeDefined()
expect(window.require).not.toBeDefined()
expect(window.define).not.toBeDefined()
RequireJS.define('test_module', [], function () {
inDefineCallback = true;
return { describe "RequireJS module creation", ->
'module_status': 'OK' inDefineCallback = undefined
}; inRequireCallback = undefined
}); it "check that we can use RequireJS define() and require() a module", ->
runs ->
inDefineCallback = false
inRequireCallback = false
RequireJS.define "test_module", [], ->
inDefineCallback = true
module_status: "OK"
RequireJS.require(['test_module'], function (test_module) { RequireJS.require ["test_module"], (test_module) ->
inRequireCallback = true; inRequireCallback = true
expect(test_module.module_status).toBe "OK"
expect(test_module.module_status).toBe('OK');
});
});
waitsFor(function () { waitsFor (->
if ((inDefineCallback !== true) || (inRequireCallback !== true)) { return false if (inDefineCallback isnt true) or (inRequireCallback isnt true)
return false; true
} ), "We should eventually end up in the defined callback", 1000
runs ->
expect(inDefineCallback).toBeTruthy()
expect(inRequireCallback).toBeTruthy()
return true
}, 'We should eventually end up in the defined callback', 1000);
runs(function () {
expect(inDefineCallback).toBeTruthy();
expect(inRequireCallback).toBeTruthy();
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment