Skip to content

Instantly share code, notes, and snippets.

@cmlenz
Created April 4, 2014 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmlenz/9975826 to your computer and use it in GitHub Desktop.
Save cmlenz/9975826 to your computer and use it in GitHub Desktop.
Can’t get even the simplest AngularJS async test to work with Karma, tried both Jasmine 2.0 and Mocha. It works when I remove the ngMock module() invocation.
angular.module('myModule', []);
describe('Async', function() {
beforeEach(function(done) {
console.log("beforeEach", done);
module('myModule', function() { // <- hangs here
console.log("got module");
setTimeout(function() {
done();
}, 100);
});
});
it("should run", function(done) {
console.log("test", done);
setTimeout(function() {
done();
}, 100);
});
afterEach(function(done) {
console.log("test", done);
setTimeout(function() {
done();
}, 100);
});
});
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: .../node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): async_mocha.spec.js
LOG: 'beforeEach', function (err){ ... }
Firefox 28.0.0 (Mac OS X 10.9) Async "before each" hook FAILED
timeout of 2000ms exceeded
Runnable.prototype.resetTimeout/this.timer<@.../node_modules/mocha/mocha.js:4254
LOG: 'test', function (err){ ... }
Firefox 28.0.0 (Mac OS X 10.9): Executed 1 of 1 (1 FAILED) ERROR (2.116 secs / 2.002 secs)
@cmlenz
Copy link
Author

cmlenz commented Apr 4, 2014

Hmm, maybe I misunderstood the ngMock module() fn.

@cmlenz
Copy link
Author

cmlenz commented Apr 4, 2014

Yes, subtly. Got it working here: https://gist.github.com/cmlenz/9978669 – although in a "real" example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment