Created
March 27, 2012 15:19
-
-
Save EndangeredMassa/2216858 to your computer and use it in GitHub Desktop.
Overwrite Jasmine's describe method for requirejs support
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
describe 'test some stuff', ['SomeModule'], -> | |
it 'testing something', -> | |
@SomeModule.act() |
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
// proof of concept; clean it up for real use | |
window.describe = function(description, depsOrTestFn, testFn) { | |
if(arguments.length === 3) { | |
_describe(description, function() { | |
jasmineContext = this; | |
var readyModules = []; | |
beforeEach(function(){ | |
waitsFor(function() { | |
require(depsOrTestFn, function() { | |
readyModules = arguments; | |
}); | |
return readyModules.length === depsOrTestFn.length; | |
}); | |
runs(function() { | |
for(var i=0; i<readyModules.length; i++) { | |
var moduleName = depsOrTestFn[0]; | |
moduleName = moduleName.split('/').pop(); | |
moduleName = moduleName.split('.'); | |
if(moduleName.length > 1) | |
moduleName.pop(); | |
moduleName = moduleName[0]; | |
console.log(moduleName); | |
this[moduleName] = readyModules[0]; | |
} | |
}); | |
}); | |
var arrayOfModules = Array.prototype.slice.call(readyModules); | |
testFn.apply(jasmineContext, arrayOfModules); | |
}); | |
} else { | |
_describe.call(this, description, depsOrTestFn); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment