Commit c5cd67a6 by valera-rozuvan Committed by Valera Rozuvan

Work on RequireJS Jasmine test.

parent f2cce07b
describe('RequireJS namespacing', function() {
beforeEach(function() {
this.addMatchers({
requirejsTobeUndefined: function() {
return (typeof requirejs === 'undefined');
},
requireTobeUndefined: function() {
return (typeof require === 'undefined');
},
defineTobeUndefined: function() {
return (typeof define === 'undefined');
},
});
});
describe "RequireJS namespacing", ->
beforeEach ->
@addMatchers
requirejsTobeUndefined: ->
typeof requirejs is "undefined"
it('check that the RequireJS object is present in the global namespace', function() {
expect(RequireJS).toEqual(jasmine.any(Object));
expect(window.RequireJS).toEqual(jasmine.any(Object));
});
requireTobeUndefined: ->
typeof require is "undefined"
it('check that requirejs(), require(), and define() are not in the global namespace', function () {
expect({}).requirejsTobeUndefined();
expect({}).requireTobeUndefined();
expect({}).defineTobeUndefined();
defineTobeUndefined: ->
typeof define is "undefined"
expect(window.requirejs).not.toBeDefined();
expect(window.require).not.toBeDefined();
expect(window.define).not.toBeDefined();
});
});
describe('RequireJS module creation', function() {
var inDefineCallback, inRequireCallback;
it "check that the RequireJS object is present in the global namespace", ->
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() {
runs(function () {
inDefineCallback = false;
inRequireCallback = false;
it "check that requirejs(), require(), and define() are not in the global namespace", ->
expect({}).requirejsTobeUndefined()
expect({}).requireTobeUndefined()
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 {
'module_status': 'OK'
};
});
describe "RequireJS module creation", ->
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) {
inRequireCallback = true;
RequireJS.require ["test_module"], (test_module) ->
inRequireCallback = true
expect(test_module.module_status).toBe "OK"
expect(test_module.module_status).toBe('OK');
});
});
waitsFor(function () {
if ((inDefineCallback !== true) || (inRequireCallback !== true)) {
return false;
}
waitsFor (->
return false if (inDefineCallback isnt true) or (inRequireCallback isnt true)
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