-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* HeroesComponent's private CSS styles */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h2>My Heroes</h2> | ||
|
||
<ul class="heroes"> | ||
<li *ngFor="let hero of heroes"> | ||
<span class="badge">{{hero.id}}</span> {{hero.name}} | ||
</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {async, ComponentFixture} from '@angular/core/testing'; | ||
import {HeroesComponent} from './heroes.component'; | ||
import {ConfigureFn, configureTests} from '@lib/testing'; | ||
import {Hero} from '../service/hero'; | ||
import {HeroService} from '../service/hero.service'; | ||
import {Subject} from 'rxjs'; | ||
|
||
describe('HeroesComponent', () => { | ||
let component: HeroesComponent; | ||
let fixture: ComponentFixture<HeroesComponent>; | ||
|
||
const mockHeroesSubject = new Subject<Hero[]>(); | ||
const mockHeroService = { | ||
getHeroes: jest.fn(() => mockHeroesSubject) | ||
}; | ||
|
||
const allHeroes: Hero[] = [ | ||
{ | ||
id: 1, | ||
name: 'Test hero 1', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Test hero 2', | ||
} | ||
]; | ||
|
||
beforeEach(async(() => { | ||
const configure: ConfigureFn = testBed => { | ||
testBed.configureTestingModule({ | ||
declarations: [HeroesComponent], | ||
providers: [{provide: HeroService, useValue: mockHeroService}] | ||
}); | ||
}; | ||
|
||
configureTests(configure).then(testBed => { | ||
fixture = testBed.createComponent(HeroesComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
})); | ||
|
||
afterEach(() => { | ||
mockHeroesSubject.complete(); | ||
}); | ||
|
||
it('should display a list of all heroes', () => { | ||
mockHeroesSubject.next(allHeroes); | ||
fixture.detectChanges(); | ||
|
||
const el = fixture.nativeElement; | ||
expect(el.textContent).toContain('Test hero 1'); | ||
expect(el.textContent).toContain('Test hero 2'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
import { Hero } from '../service/hero'; | ||
import { HeroService } from '../service/hero.service'; | ||
|
||
@Component({ | ||
selector: 'app-heroes', | ||
templateUrl: './heroes.component.html', | ||
styleUrls: ['./heroes.component.css'] | ||
}) | ||
export class HeroesComponent implements OnInit { | ||
heroes: Hero[]; | ||
|
||
constructor(private heroService: HeroService) { } | ||
|
||
ngOnInit() { | ||
this.getHeroes(); | ||
} | ||
|
||
getHeroes(): void { | ||
this.heroService.getHeroes() | ||
.subscribe(heroes => this.heroes = heroes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters