Last active
August 8, 2022 19:27
Revisions
-
kaplan81 revised this gist
Apr 26, 2021 . 1 changed file with 6 additions and 6 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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import { MyService } from './my.service'; Use stub components for shallow testing. Do not use NO_ERRORS_SCHEMA. */ const optionsDataMock: Record<string, string> = { option1: 'option1', option2: 'option2', option3: 'option3', @@ -31,15 +31,15 @@ class ChildStubComponent { @Injectable() class MyAsyncServiceMock extends MyAsyncService { myAsyncServiceMethod: jest.Mock<Observable<any[]>> = jest.fn(() => of([])); } @Injectable() class MyFromModuleServiceMock extends MyFromModuleService { observableMethod: jest.Mock<Observable<any[]>> = jest.fn(() => of([])); optionsObj: Record<string, string> = optionsDataMock; promiseMethod: jest.Mock<Promise<any[]>> = jest.fn(() => Promise.resolve([])); voidMethod: jest.Mock<void> = jest.fn(); } /* HERE YOUR SUITES (describe) */ -
kaplan81 revised this gist
Jun 22, 2020 . 1 changed file with 1 addition and 6 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 charactersOriginal file line number Diff line number Diff line change @@ -49,13 +49,8 @@ describe('MyComponent', () => { let els: ComponentSuiteElements<MyComponent>; let page: Page; let myService: MyService; beforeEach(async(() => { // myAsyncServiceMethod = new myAsyncService().myAsyncServiceMethod; // OLD // myValue = 'myValue'; // OLD TestBed.configureTestingModule({ @@ -78,7 +73,7 @@ describe('MyComponent', () => { We can also have non-mocked services here. For mocked services we directly test on their mocked methods. */ myService = TestBed.inject(MyService); }); })); -
kaplan81 revised this gist
Jun 22, 2020 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import { MyService } from './my.service'; Use stub components for shallow testing. Do not use NO_ERRORS_SCHEMA. */ const optionsDataMock: { [key: string]: any } = { option1: 'option1', option2: 'option2', option3: 'option3', -
kaplan81 revised this gist
Jun 22, 2020 . 1 changed file with 23 additions and 21 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 charactersOriginal file line number Diff line number Diff line change @@ -18,27 +18,29 @@ import { MyService } from './my.service'; Use stub components for shallow testing. Do not use NO_ERRORS_SCHEMA. */ const optionsDataMock = { option1: 'option1', option2: 'option2', option3: 'option3', }; @Component({ selector: 'pfx-child', template: '' }) class ChildStubComponent { @Input() prop: string; } @Injectable() class MyAsyncServiceMock extends MyAsyncService { myAsyncServiceMethod: () => Observable<any[]> = jest.fn(() => of([])); } @Injectable() class MyFromModuleServiceMock extends MyFromModuleService { observableMethod: () => Observable<any[]> = jest.fn(() => of([])); optionsObj = optionsDataMock; promiseMethod: () => Promise<any[]> = jest.fn(() => Promise.resolve([])); voidMethod: () => void = jest.fn(); } /* HERE YOUR SUITES (describe) */ describe('MyComponent', () => { @@ -53,17 +55,17 @@ describe('MyComponent', () => { let myValue: string; beforeEach(async(() => { /* Initialized here variables that are not depending on the fixture. */ // OLD // myAsyncServiceMethod = new myAsyncService().myAsyncServiceMethod; // OLD // myValue = 'myValue'; // OLD TestBed.configureTestingModule({ imports: [CoreModule], declarations: [MyComponent, ChildStubComponent], providers: [MyService, { provide: MyAsyncService, useClass: MyAsyncServiceMock }] }) .overrideComponent(MyComponent, { set: { providers: [{ provide: MyFromModuleService, useClass: MyFromModuleServiceMock }] } }) .compileComponents() -
kaplan81 revised this gist
Oct 19, 2018 . 1 changed file with 0 additions and 128 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 charactersOriginal file line number Diff line number Diff line change @@ -1,128 +0,0 @@ -
kaplan81 revised this gist
Oct 19, 2018 . 1 changed file with 0 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 charactersOriginal file line number Diff line number Diff line change @@ -50,9 +50,6 @@ describe('HttpClient testing', () => { // Respond with mock data, causing Observable to resolve. // Subscribe callback asserts that correct data was returned. req.flush(testData); }); it('can test HttpClient.get with matching header', () => { const testData: Data = { name: 'Test Data' }; -
kaplan81 revised this gist
Sep 28, 2018 . 1 changed file with 2 additions and 2 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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export { RouterLink } from '@angular/router'; @Directive({ selector: '[routerLink]' }) export class RouterLinkStubDirective { navigatedTo: any = null; @Input() routerLink: any; @@ -20,6 +20,6 @@ export class RouterLinkDirectiveStub { } @NgModule({ declarations: [RouterLinkStubDirective] }) export class RouterStubsModule {} -
kaplan81 revised this gist
Sep 18, 2018 . 1 changed file with 9 additions and 15 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 charactersOriginal file line number Diff line number Diff line change @@ -1,31 +1,25 @@ /* FILE TYPE: TEST HELPER */ import { Directive, HostListener, Input, NgModule } from '@angular/core'; // export for convenience. export { RouterLink } from '@angular/router'; /* tslint:disable:directive-class-suffix */ @Directive({ selector: '[routerLink]' }) export class RouterLinkDirectiveStub { navigatedTo: any = null; @Input() routerLink: any; @HostListener('click') onClick() { this.navigatedTo = this.routerLink; } } @NgModule({ declarations: [RouterLinkDirectiveStub] }) export class RouterStubsModule {} -
kaplan81 revised this gist
Sep 18, 2018 . 1 changed file with 15 additions and 9 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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,31 @@ /* FILE TYPE: TEST HELPER */ import { Directive, Input } from '@angular/core'; // export for convenience. export { RouterLink} from '@angular/router'; /* tslint:disable:directive-class-suffix */ // #docregion router-link @Directive({ selector: '[routerLink]', host: { '(click)': 'onClick()' } }) export class RouterLinkDirectiveStub { @Input('routerLink') linkParams: any; navigatedTo: any = null; onClick() { this.navigatedTo = this.linkParams; } } // #enddocregion router-link /// Dummy module to satisfy Angular Language service. Never used. import { NgModule } from '@angular/core'; @NgModule({ declarations: [ RouterLinkDirectiveStub ] }) export class RouterStubsModule {} -
kaplan81 revised this gist
Sep 6, 2018 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,3 @@ # Testing > Helpers and examples for unit testing on Angular applications and libraries. -
kaplan81 revised this gist
Sep 6, 2018 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,3 @@ # Testing > Helper classes and example specs for unit testing purposes on Angular applications and libraries. -
kaplan81 revised this gist
Sep 6, 2018 . 2 changed files with 3 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # testing > Helper classes and example specs for unit testing purposes on Angular applications and libraries. -
kaplan81 revised this gist
Sep 6, 2018 . 1 changed file with 1 addition and 0 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ Hello World -
kaplan81 revised this gist
Sep 6, 2018 . 1 changed file with 13 additions and 11 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 charactersOriginal file line number Diff line number Diff line change @@ -5,11 +5,11 @@ import { ComponentFixture } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; export interface ComponentSuiteElements<H, N = any> { host: ComponentTestingElement<H>; nested?: ComponentTestingElement<N>; } export interface ComponentTestingElement<T> { component: T; debugEl: DebugElement; nativeEl: Element | HTMLElement; @@ -22,7 +22,7 @@ export class ComponentSuite<H, N = any> { this.setElements(); } private getHost(): ComponentTestingElement<H> { const component: H = this.fixture.componentInstance; const debugEl: DebugElement = this.fixture.debugElement; const nativeEl: Element | HTMLElement = debugEl.nativeElement; @@ -31,16 +31,16 @@ export class ComponentSuite<H, N = any> { } private getIntegrationElements(): ComponentSuiteElements<H, N> { const host: ComponentTestingElement<H> = this.getHost(); const nested: ComponentTestingElement<N> = this.getNested(host.debugEl); return { host, nested }; } private getNested(hostDebugEl: DebugElement): ComponentTestingElement<N> { const debugEl: DebugElement = hostDebugEl.query(By.css(this.selector)); const component: N = debugEl.componentInstance; const nativeEl: Element | HTMLElement = debugEl.nativeElement; @@ -53,8 +53,10 @@ export class ComponentSuite<H, N = any> { } private setElements(): void { if (this.selector) { this.elements = this.getIntegrationElements(); } else { this.elements = this.getShallowElements(); } } } -
kaplan81 revised this gist
Sep 5, 2018 . 1 changed file with 3 additions and 5 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 charactersOriginal file line number Diff line number Diff line change @@ -53,10 +53,8 @@ export class ComponentSuite<H, N = any> { } private setElements(): void { this.elements = this.selector ? this.getIntegrationElements() : (this.elements = this.getShallowElements()); } } -
kaplan81 revised this gist
Sep 5, 2018 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -95,7 +95,7 @@ describe('MyComponent', () => { it('should generate as many titles as contents', () => { fixture.detectChanges(); const titles: number = els.host.debugEl.queryAll(By.css('.title')).length; const contents: number = els.host.component.contents.toArray().length; expect(titles).toEqual(contents); -
kaplan81 revised this gist
Sep 5, 2018 . 1 changed file with 2 additions and 2 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 charactersOriginal file line number Diff line number Diff line change @@ -107,11 +107,11 @@ describe('MyComponent', () => { myAsyncServiceMethod.and.returnValue(q$); fixture.detectChanges(); // ngOnInit() expect(els.host.nativeEl.textContent).toBe('...'); getTestScheduler().flush(); // flush the observables fixture.detectChanges(); // update view expect(els.host.nativeEl.textContent).toBe(myValue); }); }); -
kaplan81 revised this gist
Sep 5, 2018 . 1 changed file with 14 additions and 12 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,8 @@ import { Component, DebugElement, Input } from '@angular/core'; import { ComponentFixture, TestBed, async } from '@angular/core/testing'; // Use Typescript path mapping to import test helpers. import { CoreModule } from '@app/core/core.module'; import { Page } from '@testing'; import { ComponentSuite, ComponentSuiteElements } from '@testing'; import { cold, getTestScheduler } from 'jasmine-marbles'; import { of } from 'rxjs/observable/of'; import { MyAsyncService } from './my-async.service'; @@ -43,9 +44,7 @@ const myFromModuleServiceMock = jest.fn<MyFromModuleService>(() => ({ describe('MyComponent', () => { /* Declare all variables that you need for your specs. */ let fixture: ComponentFixture<MyComponent>; let els: ComponentSuiteElements<MyComponent>; let page: Page; let myService: MyService; // Methods from mocked services. @@ -70,14 +69,7 @@ describe('MyComponent', () => { .compileComponents() .then(() => { fixture = TestBed.createComponent(MyComponent); els = new ComponentSuite<MyComponent>(fixture).elements; /* User the Page class (or extend it) to encapsulate component's complexity. */ page = new Page(component, debugEl, nativeEl); /* @@ -98,6 +90,16 @@ describe('MyComponent', () => { /* We use Jest snapshot testing instead of the usual matcher. */ expect(fixture).toMatchSnapshot(); }); /* Shallow test example with ComponentSuite helper class */ it('should generate as many titles as contents', () => { fixture.detectChanges(); const titles: number = els.host.debugEl.queryAll(By.css('.label')).length; const contents: number = els.host.component.contents.toArray().length; expect(titles).toEqual(contents); }); /* Work with jasmine marbles to test observables. */ it('should test with jasmine marbles', () => { -
kaplan81 revised this gist
Sep 5, 2018 . 1 changed file with 2 additions and 0 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ /* FILE TYPE: TEST HELPER */ import { DebugElement } from '@angular/core'; import { ComponentFixture } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -
kaplan81 revised this gist
Sep 5, 2018 . 1 changed file with 60 additions and 0 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ import { DebugElement } from '@angular/core'; import { ComponentFixture } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; export interface ComponentSuiteElements<H, N = any> { host: ComponentTestingElements<H>; nested?: ComponentTestingElements<N>; } export interface ComponentTestingElements<T> { component: T; debugEl: DebugElement; nativeEl: Element | HTMLElement; } export class ComponentSuite<H, N = any> { elements: ComponentSuiteElements<H, N>; constructor(private fixture: ComponentFixture<H>, private selector?: string) { this.setElements(); } private getHost(): ComponentTestingElements<H> { const component: H = this.fixture.componentInstance; const debugEl: DebugElement = this.fixture.debugElement; const nativeEl: Element | HTMLElement = debugEl.nativeElement; return { component, debugEl, nativeEl }; } private getIntegrationElements(): ComponentSuiteElements<H, N> { const host: ComponentTestingElements<H> = this.getHost(); const nested: ComponentTestingElements<N> = this.getNested(host.debugEl); return { host, nested }; } private getNested(hostDebugEl: DebugElement): ComponentTestingElements<N> { const debugEl: DebugElement = hostDebugEl.query(By.css(this.selector)); const component: N = debugEl.componentInstance; const nativeEl: Element | HTMLElement = debugEl.nativeElement; return { component, debugEl, nativeEl }; } private getShallowElements(): ComponentSuiteElements<H> { return { host: this.getHost() }; } private setElements(): void { if (this.selector) { this.elements = this.getIntegrationElements(); } else { this.elements = this.getShallowElements(); } } } -
kaplan81 revised this gist
Sep 5, 2018 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -96,7 +96,7 @@ describe('MyComponent', () => { */ fixture.detectChanges(); /* We use Jest snapshot testing instead of the usual matcher. */ expect(fixture).toMatchSnapshot(); }); /* Work with jasmine marbles to test observables. */ -
kaplan81 revised this gist
Jun 20, 2018 . 1 changed file with 1 addition and 0 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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { Directive, HostListener, Input, NgModule } from '@angular/core'; export { RouterLink } from '@angular/router'; /* tslint:disable:directive-class-suffix */ /* tslint:disable:directive-selector */ @Directive({ selector: '[routerLink]' }) -
kaplan81 revised this gist
Jun 20, 2018 . 1 changed file with 3 additions and 4 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ // export for convenience. export { ActivatedRoute } from '@angular/router'; import { convertToParamMap, Data, ParamMap, Params } from '@angular/router'; import { Observable, of, BehaviorSubject } from 'rxjs'; export interface ActivatedRouteSnapshotStub { data?: Data; @@ -20,9 +20,8 @@ export class ActivatedRouteStub { data: Observable<Data>; snapshot: ActivatedRouteSnapshotStub; readonly paramMap: Observable<ParamMap>; // ReplaySubject is not compatible with snapshot testing since it produces a window timestamp. private subject = new BehaviorSubject<ParamMap>(null); constructor(init: ActivatedRouteProps = {}) { this.paramMap = this.subject.asObservable(); -
kaplan81 revised this gist
Jun 20, 2018 . No changes.There are no files selected for viewing
-
kaplan81 revised this gist
Jun 13, 2018 . 1 changed file with 6 additions and 2 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 charactersOriginal file line number Diff line number Diff line change @@ -25,12 +25,16 @@ export class ActivatedRouteStub { private subject = new ReplaySubject<ParamMap>(); constructor(init: ActivatedRouteProps = {}) { this.paramMap = this.subject.asObservable(); if (init.initialSnapshot) this.snapshot = init.initialSnapshot; if (init.initialData) { this.data = of(init.initialData); this.setParamMap(init.initialParams); } } setParamMap(params?: Params) { this.subject.next(convertToParamMap(params)); } } -
kaplan81 revised this gist
Jun 13, 2018 . 1 changed file with 0 additions and 27 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 charactersOriginal file line number Diff line number Diff line change @@ -1,27 +0,0 @@ -
kaplan81 revised this gist
Jun 13, 2018 . 1 changed file with 12 additions and 11 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 charactersOriginal file line number Diff line number Diff line change @@ -2,33 +2,34 @@ // export for convenience. export { ActivatedRoute } from '@angular/router'; import { convertToParamMap, Data, ParamMap, Params } from '@angular/router'; import { Observable, of, ReplaySubject } from 'rxjs'; export interface ActivatedRouteSnapshotStub { data?: Data; paramMap?: ParamMap; } export interface ActivatedRouteProps { initialData?: Data; initialSnapshot?: ActivatedRouteSnapshotStub; initialParams?: Params; } export class ActivatedRouteStub { data: Observable<Data>; snapshot: ActivatedRouteSnapshotStub; readonly paramMap: Observable<ParamMap>; // Use a ReplaySubject to share previous values with subscribers // and pump new values into the `paramMap` observable private subject = new ReplaySubject<ParamMap>(); constructor(init: ActivatedRouteProps = {}) { this.data = of(init.initialData); this.paramMap = this.subject.asObservable(); this.setParamMap(init.initialParams); } setParamMap(params?: Params) { this.subject.next(convertToParamMap(params)); } -
kaplan81 revised this gist
Jun 12, 2018 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ * * Using `asap` scheduler - as in `of(value, asap)` - doesn't work either. */ import { defer } from 'rxjs'; /** Create async observable that emits-once and completes * after a JS engine turn */ -
kaplan81 revised this gist
Jun 12, 2018 . 1 changed file with 1 addition 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 charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,7 @@ // export for convenience. export { ActivatedRoute } from '@angular/router'; import { convertToParamMap, ParamMap, Params } from '@angular/router'; import { Observable, of, ReplaySubject } from 'rxjs'; export interface ActivatedRouteProps { initialParams?: Params; -
kaplan81 revised this gist
Jun 12, 2018 . 1 changed file with 15 additions and 7 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 charactersOriginal file line number Diff line number Diff line change @@ -2,26 +2,34 @@ // export for convenience. export { ActivatedRoute } from '@angular/router'; import { convertToParamMap, ParamMap, Params } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { of } from 'rxjs/observable/of'; import { ReplaySubject } from 'rxjs/ReplaySubject'; export interface ActivatedRouteProps { initialParams?: Params; initialData?: any; } /** * An ActivateRoute test double with a `paramMap` observable. * Use the `setParamMap()` method to add the next `paramMap` value. */ export class ActivatedRouteStub { /** The mock paramMap observable */ readonly paramMap: Observable<any>; readonly data: Observable<any>; // Use a ReplaySubject to share previous values with subscribers // and pump new values into the `paramMap` observable private subject = new ReplaySubject<ParamMap>(); constructor(init: ActivatedRouteProps = {}) { this.paramMap = this.subject.asObservable(); this.data = of(init.initialData); this.setParamMap(init.initialParams); } /** Set the paramMap observables's next value */ setParamMap(params?: Params) { this.subject.next(convertToParamMap(params));
NewerOlder