What is the correct way of unit testing a service returning an Observable result in Angular 2? Let\'s say we have a getCars method in a CarService service class:
<
AsyncTestCompleter
is deprecated https://github.com/angular/angular/issues/5443. injectAsync
replaced it
https://github.com/angular/angular/issues/4715#issuecomment-149288405
but injectAsync
is now also deprecated
injectAsync
is not deprecated anymore https://github.com/angular/angular/pull/5721 (see also comment from @ErdincGuzel)
it('retrieves all the cars', injectAsync( [CarService], ( carService ) => {
var c = PromiseWrapper.completer();
carService.getCars().subscribe( result => {
expect(result.length).toBeGreaterThan(0);
c.resolve();
} );
return c.promise;
}) );