|
| 1 | +import { TestBed, fakeAsync, tick, async, ComponentFixture, inject } from '@angular/core/testing'; |
| 2 | +import { HeroComponent } from '../hero.component/hero.component'; |
| 3 | +import { HeroesComponent } from './heroes.component'; |
| 4 | +import { HeroService } from '../hero.service/hero.service'; |
| 5 | +import { Router } from '@angular/router'; |
| 6 | +import { By } from '@angular/platform-browser'; |
| 7 | + |
| 8 | +describe('HeroDetailComponent (shallow tests)', () => { |
| 9 | + let fixture: ComponentFixture<HeroesComponent>; |
| 10 | + let component: HeroesComponent; |
| 11 | + let element; |
| 12 | + let heroes = [ |
| 13 | + {id: 3, name: 'Magneta', strength: 4}, |
| 14 | + {id: 4, name: 'Dynama', strength: 2} |
| 15 | + ]; |
| 16 | + |
| 17 | + beforeEach(() => { |
| 18 | + |
| 19 | + const mockHeroService = { |
| 20 | + getHeros: () => Promise.resolve(heroes), |
| 21 | + delete: () => Promise.resolve() |
| 22 | + }; |
| 23 | + |
| 24 | + const mockRouter = {}; |
| 25 | + |
| 26 | + TestBed.configureTestingModule({ |
| 27 | + imports: [ |
| 28 | + ], |
| 29 | + declarations: [ |
| 30 | + HeroComponent, |
| 31 | + HeroesComponent |
| 32 | + ], |
| 33 | + providers: [ |
| 34 | + { provide: HeroService, useValue: mockHeroService }, |
| 35 | + { provide: Router, useValue: mockRouter }, |
| 36 | + ], |
| 37 | + schemas: [ |
| 38 | + // NO_ERRORS_SCHEMA will hide that angular doesn't know about ngModel |
| 39 | + ] |
| 40 | + }); |
| 41 | + |
| 42 | + fixture = TestBed.createComponent(HeroesComponent); |
| 43 | + component = fixture.componentInstance; |
| 44 | + element = fixture.nativeElement; |
| 45 | + }); |
| 46 | + |
| 47 | + describe('initial display', () => { |
| 48 | + it('should show the hero id and name for each hero', fakeAsync(() => { |
| 49 | + console.log(2.5); |
| 50 | + expect(3).toBe(3); |
| 51 | + })) |
| 52 | + }); |
| 53 | + |
| 54 | + it('should select the hero when the hero is clicked'); |
| 55 | + |
| 56 | + it('should delete the hero when the delete button is clicked'); |
| 57 | + |
| 58 | +}); |
| 59 | + |
| 60 | +function createEvent(eventName: string, bubbles = false, cancelable = false) { |
| 61 | + let evt = document.createEvent('CustomEvent'); // MUST be 'CustomEvent' |
| 62 | + evt.initCustomEvent(eventName, bubbles, cancelable, null); |
| 63 | + return evt; |
| 64 | +} |
| 65 | + |
| 66 | +function getHeadingText(fixture) { |
| 67 | + return fixture.debugElement.query(By.css('h2')).nativeElement.textContent; |
| 68 | +} |
| 69 | + |
0 commit comments