de1c518770c7663b1206f7ca4e2ee3346b4a9c9c
[examples/angular-tour-of-heroes] / src / app / hero.service.spec.ts
1 import { TestBed} from '@angular/core/testing';
2 import { TestScheduler } from 'rxjs/testing';
3
4 import { HeroService } from './hero.service';
5 import { HttpClientTestingModule } from '@angular/common/http/testing';
6
7 describe('HeroService', () => {
8   let service: HeroService;
9   let scheduler: TestScheduler;
10
11   beforeEach(() =>  {
12     TestBed.configureTestingModule({
13       imports: [ HttpClientTestingModule ]
14     });
15     service = TestBed.inject(HeroService);
16     scheduler = new TestScheduler(((actual, expected) => {
17       expect(actual).toEqual(expected);
18     }));
19   });
20
21   it('should be created', () => {
22     expect(service).toBeTruthy();
23   });
24
25   it('get for id=0 should return an empty Observable', () =>
26     scheduler.run(({expectObservable}) => {
27       expectObservable(service.getHero(0)).toBe('(|)');
28     })
29   );
30
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' }});
34     })
35   );
36 });