Jasmine 2.0 async done() and angular-mocks inject() in same test it()

huston007 picture huston007 · Aug 12, 2014 · Viewed 19.2k times · Source

My usual test case looks like

it("should send get request", inject(function(someServices) {
     //some test
}));

And Jasmine 2.0 async test should look like

it("should send get request", function(done) {
     someAsync.then(function(){
         done();
     });
});

How can I use both done and inject in one test?

Answer

Scott Boring picture Scott Boring · Dec 28, 2014

This should work; I ran into the same problem when I updated to Jasmine 2.0

it("should send get request", function(done) {
    inject(function(someServices) {
        //some async test
        done();
    })(); // function returned by 'inject' has to be invoked
});