-import { TestBed } from '@angular/core/testing';
+import { TestBed} from '@angular/core/testing';
+import { TestScheduler } from 'rxjs/testing';
import { HeroService } from './hero.service';
+import { Hero } from './hero';
+import {map} from 'rxjs/operators';
describe('HeroService', () => {
- beforeEach(() => TestBed.configureTestingModule({}));
+ let service: HeroService;
+ let scheduler: TestScheduler;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ 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' }});
+ })
+ );
});