Skip to content

Instantly share code, notes, and snippets.

@jedahu
Last active December 13, 2015 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedahu/4973309 to your computer and use it in GitHub Desktop.
Save jedahu/4973309 to your computer and use it in GitHub Desktop.
Replacement async 'it' for testing AngularJs with Mocha.
function ngIt($injector) {
return function(text, fn) {
it(text, function(done) {
var $rootScope = $injector.get('$rootScope')
, fin
, finished = function(err) {
fin = true;
done(err);
};
fn(finished);
while (!fin) {$rootScope.$digest()}
$rootScope.$digest();
})
}
}
// Set up like this at top of test file:
const $it = ngIt(angular.injector(['ng', 'ModuleA']));
// Then use in place of `it`.
; export const ngIt = ($injector) =>
(text, fn) =>
it(text, (done) =>
{ const $rootScope = $injector.get('$rootScope')
; let fin
; const finished = (err) =>
{ fin = true
; done(err)
}
; fn(finished)
; while (!fin) {$rootScope.$digest()}
; $rootScope.$digest()
})
// Set up like this at top of test file:
; const $it = ngIt(angular.injector(['ng', 'ModuleA']))
// Then use in place of `it`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment