Skip to content

Instantly share code, notes, and snippets.

@bolshakov
Forked from madtrick/example_spec
Created September 8, 2017 12:06
Show Gist options
  • Save bolshakov/12a314269302fae5e1c7af379a0db66d to your computer and use it in GitHub Desktop.
Save bolshakov/12a314269302fae5e1c7af379a0db66d to your computer and use it in GitHub Desktop.
Jasmine and RequireJS together. Easy way
require ['fileA', 'fileB'], (A, B) ->
describe "An example", ->
it "depends on A and B"
/*
* 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