Created
June 26, 2014 13:27
-
-
Save spoike/6c1500985cc516e175dc to your computer and use it in GitHub Desktop.
Utility method for your Mocha tests that loads in your modules with RequireJS.
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
// Needs RequireJS's `require` and mocha's `before` | |
/** | |
* Works like mocha's `before` function but enables you to load in dependencies | |
* as well. | |
* | |
* @param deps [Array] the dependencies passed on to RequireJS | |
* @param callback [Function] the callback with loaded dependencies as arguments | |
*/ | |
requireBefore = function(deps, callback) { | |
before(function(done) { | |
require(deps, function() { | |
callback.apply(undefined, arguments); | |
done(); | |
}); | |
}); | |
}; | |
// Example Usage: | |
requireBefore(['dep1', 'dep2'], function(dep1, dep2) { | |
// dep1 and dep2 are available here asynchonously but subsequent tests are not | |
// run until after the dependencies are loaded and this callback is executed | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment