Created
September 15, 2013 10:37
-
-
Save madtrick/6569580 to your computer and use it in GitHub Desktop.
Jasmine and RequireJS together. Easy way
This file contains 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
require ['fileA', 'fileB'], (A, B) -> | |
describe "An example", -> | |
it "depends on A and B" |
This file contains 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
/* | |
* Little snippet to make Jasmine and RequireJS play nice together. | |
* | |
* */ | |
(function(){ | |
var originalRequire = require; | |
var originalJasmineExecute = jasmine.getEnv().execute; | |
var requiresCounter = 0; | |
require = function (deps, callback){ | |
requiresCounter++; | |
var newCallback = function(){ | |
requiresCounter--; | |
callback.apply(this, Array.prototype.slice.call(arguments)); | |
if (requiresCounter === 0){ | |
// Trigger jasmine execution | |
originalJasmineExecute.call(jasmine.getEnv()); | |
} | |
} | |
originalRequire.call(this, deps, newCallback); | |
}; | |
jasmine.getEnv().execute = function(){}; | |
originalRequire.config({baseUrl : "http://localhost:8000/public/assets/"}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup for using Jasmine (guard-jasmine) and RequireJS.
After looking for a way to use Jasmine and RequireJS together I came out with the following solution which I think is simpler compared to others.
Steps:
In jasmine.yml require only the requirejs file as src_files. For example:
Create and include the requirejs_helper (included above). Customize requirejs to your needs:
This helpers keeps count of the required files and only starts the execution of Jasmine when all these files are loaded.
After this simple steps write your specs and enjoy