X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fhero.service.spec.ts;h=de1c518770c7663b1206f7ca4e2ee3346b4a9c9c;hb=b52b79a39e71932d1413cfbeca4d4ae3a50fe35b;hp=082791a7adcdfe503689a9a78896bf7ba84c42a8;hpb=ef15a90ba71bcff7765f089af11e2ad22752a352;p=examples%2Fangular-tour-of-heroes diff --git a/src/app/hero.service.spec.ts b/src/app/hero.service.spec.ts index 082791a..de1c518 100644 --- a/src/app/hero.service.spec.ts +++ b/src/app/hero.service.spec.ts @@ -1,12 +1,36 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed} from '@angular/core/testing'; +import { TestScheduler } from 'rxjs/testing'; import { HeroService } from './hero.service'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; describe('HeroService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + let service: HeroService; + let scheduler: TestScheduler; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ HttpClientTestingModule ] + }); + service = TestBed.inject(HeroService); + scheduler = new TestScheduler(((actual, expected) => { + expect(actual).toEqual(expected); + })); + }); it('should be created', () => { - const service: HeroService = TestBed.get(HeroService); expect(service).toBeTruthy(); }); + + it('get for id=0 should return an empty Observable', () => + scheduler.run(({expectObservable}) => { + expectObservable(service.getHero(0)).toBe('(|)'); + }) + ); + + it('get for id=11 should return an Observable, that contains the hero with id 11', () => + scheduler.run(({expectObservable}) => { + expectObservable(service.getHero(11)).toBe('(a|)', { a: { id: 11, name: 'Dr Nice' }}); + }) + ); });