This file contains hidden or 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
import { fakeAsync, tick } from '@angular/core/testing'; | |
import { asapScheduler, of as observableOf, Subject } from 'rxjs'; | |
import { takeUntil } from 'rxjs/operators'; | |
import { femaleMarvelHeroes } from '../../test/female-marvel-heroes'; | |
import { Hero } from '../hero'; | |
import { HeroService } from '../hero.service'; | |
import { HeroesContainerComponent } from './heroes.container'; | |
describe(HeroesContainerComponent.name, () => { |
This file contains hidden or 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
describe('emits all heroes', () => { | |
it('all heroes are emitted after subscribing', () => { | |
expect(observer).toHaveBeenCalledWith(femaleMarvelHeroes); | |
}); | |
it(`delegates to ${HeroService.name}`, () => { | |
expect(heroServiceStub.getHeroes).toHaveBeenCalledTimes(1); | |
}); | |
}); |
This file contains hidden or 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
describe('adds a hero', () => { | |
it('emits the specified hero when server responds', fakeAsync(() => { | |
const wonderWoman = 'Wonder Woman'; | |
container.add(wonderWoman); | |
tick(); | |
expect(observer).toHaveBeenCalledWith([ | |
...femaleMarvelHeroes, | |
{ id: 42, name: wonderWoman }, |
This file contains hidden or 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
it(`delegates to ${HeroService.name}`, () => { | |
const hawkeye = 'Hawkeye (Kate Bishop)'; | |
container.add(hawkeye); | |
expect(heroServiceStub.addHero).toHaveBeenCalledTimes(1); | |
expect(heroServiceStub.addHero).toHaveBeenCalledWith({ name: hawkeye }); | |
}); |
This file contains hidden or 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
it('does not emit the specified hero when server fails', fakeAsync(() => { | |
heroServiceStub.addHero.and.returnValue( | |
throwError(new Error('server error'), asapScheduler)); | |
const scarletWitch = 'Scarlet Witch'; | |
container.add(scarletWitch); | |
tick(); | |
expect(observer).not.toHaveBeenCalledWith([ | |
...femaleMarvelHeroes, |
This file contains hidden or 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
Horizontal layer | Examples | |
---|---|---|
Business logic | Application-specific logic, domain logic, validation rules | |
Persistence | WebStorage, IndexedDB, File System Access API, HTTP, WebSocket, GraphQL, Firebase, Meteor | |
Messaging | WebRTC, WebSocket, Push API, Server-Sent Events | |
I/O | Web Bluetooth, WebUSB, NFC, camera, microphone, proximity sensor, ambient light sensor | |
Presentation | DOM manipulation, event listeners, formatting | |
User interaction | UI behaviour, form validation | |
State management | Application state management, application-specific events |
This file contains hidden or 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
interface Person { | |
readonly age: number; | |
readonly firstName: string; | |
readonly lastName: string; | |
} | |
const bill: Person = { | |
age: 62, | |
firstName: 'Bill', | |
lastName: 'Gates', |
This file contains hidden or 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
import { Component } from '@angular/core'; | |
import { Hero } from '../hero'; | |
@Component({ | |
selector: 'app-heroes', | |
templateUrl: './heroes.component.html', | |
styleUrls: ['./heroes.component.css'] | |
}) | |
export class HeroesComponent { |
This file contains hidden or 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
import { asapScheduler, of as observableOf } from 'rxjs'; | |
import { femaleMarvelHeroes } from '../../test/female-marvel-heroes'; | |
import { Hero } from '../hero'; | |
import { HeroService } from '../hero.service'; | |
import { HeroesContainerComponent } from './heroes.container'; | |
describe(HeroesContainerComponent.name, () => { | |
function createHeroServiceStub(): jasmine.SpyObj<HeroService> { | |
const stub: jasmine.SpyObj<HeroService> = jasmine.createSpyObj( |
This file contains hidden or 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
import { fakeAsync, tick } from '@angular/core/testing'; | |
import { Subject } from 'rxjs'; | |
import { takeUntil } from 'rxjs/operators'; | |
import { HeroService } from '../hero.service'; | |
import { HeroesContainerComponent } from './heroes.container'; | |
describe(HeroesContainerComponent.name, () => { | |
let container: HeroesContainerComponent; | |
const destroy: Subject<void> = new Subject(); |