Created
March 5, 2012 21:21
-
-
Save efeminella/1981184 to your computer and use it in GitHub Desktop.
RequireJS Test Environment Module Definition Loader
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
/* | |
* Defines a utility method on the requirejs global which returns a | |
* requirejs module definition dependency so as to circumvent having | |
* to explicitly load test cased (Jasmine, QUnit etc.) as require | |
* dependencies. | |
* | |
* // In a Test/Spec, simply invoke getModule to resolve a require js | |
* // module definition without implementing Tests/Specs as require js | |
* // modules. | |
* var SomeModule = require.getModule( 'SomeModule' ); | |
*/ | |
( function( require ) | |
{ | |
if ( require ) | |
{ | |
var contexts = require.s.contexts['_'], | |
defined = contexts.defined; | |
require.getModule = function( name ) | |
{ | |
var module = defined[ name ]; | |
if ( !module ) | |
{ | |
throw new Error( "Module '" + name + "' has not been defined." ); | |
} | |
return module; | |
} | |
} | |
})( require ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment