I am using Jasmine 2.0 and require.js. I cannot get the async tests to work properly when I put the async code in a beforeEach function. My it statement is still running before the async call finishes.
Here is my spec:
describe("App Model :: ", function() {
var AppModel;
beforeEach(function(done) {
require(['models/appModel'], function(AppModel) {
AppModel = AppModel;
done();
});
});
// THIS SPEC FAILS AND RUNS BEFORE ASYNC CALL
it("should exist", function(done) {
this.appModel = new AppModel()
expect(this.appModel).toBeDefined();
done();
});
// THIS SPEC PASSES
it("should still exist", function(done) {
require(['models/appModel'], function(AppModel) {
this.appModel2 = new AppModel()
expect(this.appModel2).toBeDefined();
done();
});
});
});
The first spec fails but the second spec passes, when I include the async within the it
.
Ideally, I'd like the beforeEach
async to work rather than being not DRY and copying each require into the individual it statements.
Any tips?