1 import { TestBed} from '@angular/core/testing';
2 import { TestScheduler } from 'rxjs/testing';
4 import { HeroService } from './hero.service';
5 import { HttpClientTestingModule } from '@angular/common/http/testing';
7 describe('HeroService', () => {
8 let service: HeroService;
9 let scheduler: TestScheduler;
12 TestBed.configureTestingModule({
13 imports: [ HttpClientTestingModule ]
15 service = TestBed.inject(HeroService);
16 scheduler = new TestScheduler(((actual, expected) => {
17 expect(actual).toEqual(expected);
21 it('should be created', () => {
22 expect(service).toBeTruthy();
25 it('get for id=0 should return an empty Observable', () =>
26 scheduler.run(({expectObservable}) => {
27 expectObservable(service.getHero(0)).toBe('(|)');
31 it('get for id=11 should return an Observable, that contains the hero with id 11', () =>
32 scheduler.run(({expectObservable}) => {
33 expectObservable(service.getHero(11)).toBe('(a|)', { a: { id: 11, name: 'Dr Nice' }});