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?
To add to the answer of @Scott Boring and to the comment of @WhiteAngel who mentionned that the code inside inject was never called.
This worked for me:
For Angular 5.2.0: @scott-boring's approach did not work for me. What did work is using the
TestBed.get()
to get the services instead ofinject()
, as described in the docs:This should work; I ran into the same problem when I updated to Jasmine 2.0
You could write the test like that:
An IMPORTANT note is the brackets after the
inject
call. Eg.If you look at the type of
inject
:You can see it returns a function, so you were getting no output because you forgot to call the function!!
If you think about it, it makes sense that it returns a function, because
it
takes a function!So the extra parentheses should solve all problem!
Working Example: