Created
May 11, 2011 16:12
-
-
Save mathieul/966776 to your computer and use it in GitHub Desktop.
Require files using RequireJS before running Jasmine specs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* jasmine.requirejs() returns a function that will load the file(s) required | |
* and will wait until it's done before proceeding with running specs. | |
* The function returned is intended to be passed to beforeEach() so the file(s) | |
* is(are) loaded before running each spec. | |
* | |
* Syntax: | |
* | |
* jasmine.requirejs(options, files) | |
* or | |
* jasmine.requirejs(files) | |
* | |
* Where: | |
* - options is a configuration object like the one you | |
* can bass to RequireJS require() function (i.e.: baseUrl, paths, etc...) | |
* and | |
* - files is an array of files to require (i.e.: ['lib/common', 'views/main']) | |
* | |
* Example: | |
* | |
* beforeEach(jasmine.requirejs({ | |
* baseUrl: '/public/javascripts' | |
* }, [ | |
* 'lib/app.help-mgr' | |
* ])); | |
*/ | |
jasmine.requirejs = function () { | |
var params = Array.prototype.slice.call(arguments), | |
isLoaded = false, | |
files; | |
files = arguments[0].length ? arguments[0] : arguments[1]; | |
files = files.join(', '); | |
return function () { | |
require.apply(null, params.concat(function () { | |
isLoaded = true; | |
})); | |
waitsFor(function () { | |
return isLoaded; | |
}, 'file(s) to be required/loaded: ' + files); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now with the code examples I get it. Thanks for taking the time to post them