Last active
December 13, 2015 20:58
-
-
Save jedahu/4973309 to your computer and use it in GitHub Desktop.
Replacement async 'it' for testing AngularJs with Mocha.
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
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`. |
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
; 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