@ -9,7 +9,7 @@
|
||||
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {RouterTestingModule} from '@angular/router/testing';
|
||||
import {Observable, Observer, of } from 'rxjs';
|
||||
import {Observable, Observer, of} from 'rxjs';
|
||||
import {every, mergeMap} from 'rxjs/operators';
|
||||
import {TestScheduler} from 'rxjs/testing';
|
||||
|
||||
@ -23,13 +23,18 @@ describe('prioritizedGuardValue operator', () => {
|
||||
let router: Router;
|
||||
const TF = {T: true, F: false};
|
||||
|
||||
beforeEach(() => { TestBed.configureTestingModule({imports: [RouterTestingModule]}); });
|
||||
beforeEach(() => { testScheduler = new TestScheduler(assertDeepEquals); });
|
||||
beforeEach(() => { router = TestBed.inject(Router); });
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({imports: [RouterTestingModule]});
|
||||
});
|
||||
beforeEach(() => {
|
||||
testScheduler = new TestScheduler(assertDeepEquals);
|
||||
});
|
||||
beforeEach(() => {
|
||||
router = TestBed.inject(Router);
|
||||
});
|
||||
|
||||
it('should return true if all values are true', () => {
|
||||
testScheduler.run(({hot, cold, expectObservable}) => {
|
||||
|
||||
const a = cold(' --(T|)', TF);
|
||||
const b = cold(' ----------(T|)', TF);
|
||||
const c = cold(' ------(T|)', TF);
|
||||
@ -38,13 +43,15 @@ describe('prioritizedGuardValue operator', () => {
|
||||
const expected = ' -------------T--';
|
||||
|
||||
expectObservable(source.pipe(prioritizedGuardValue()))
|
||||
.toBe(expected, TF, /* an error here maybe */);
|
||||
.toBe(
|
||||
expected,
|
||||
TF,
|
||||
/* an error here maybe */);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if observables to the left of false have produced a value', () => {
|
||||
testScheduler.run(({hot, cold, expectObservable}) => {
|
||||
|
||||
const a = cold(' --(T|)', TF);
|
||||
const b = cold(' ----------(T|)', TF);
|
||||
const c = cold(' ------(F|)', TF);
|
||||
@ -53,13 +60,15 @@ describe('prioritizedGuardValue operator', () => {
|
||||
const expected = ' -------------F--';
|
||||
|
||||
expectObservable(source.pipe(prioritizedGuardValue()))
|
||||
.toBe(expected, TF, /* an error here maybe */);
|
||||
.toBe(
|
||||
expected,
|
||||
TF,
|
||||
/* an error here maybe */);
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore results for unresolved sets of Observables', () => {
|
||||
testScheduler.run(({hot, cold, expectObservable}) => {
|
||||
|
||||
const a = cold(' --(T|)', TF);
|
||||
const b = cold(' -------------(T|)', TF);
|
||||
const c = cold(' ------(F|)', TF);
|
||||
@ -71,13 +80,15 @@ describe('prioritizedGuardValue operator', () => {
|
||||
const expected = ' ------------T---';
|
||||
|
||||
expectObservable(source.pipe(prioritizedGuardValue()))
|
||||
.toBe(expected, TF, /* an error here maybe */);
|
||||
.toBe(
|
||||
expected,
|
||||
TF,
|
||||
/* an error here maybe */);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return UrlTree if higher priority guards have resolved', () => {
|
||||
testScheduler.run(({hot, cold, expectObservable}) => {
|
||||
|
||||
const urlTree = router.parseUrl('/');
|
||||
|
||||
const urlLookup = {U: urlTree};
|
||||
@ -91,13 +102,15 @@ describe('prioritizedGuardValue operator', () => {
|
||||
const expected = ' -------------U---';
|
||||
|
||||
expectObservable(source.pipe(prioritizedGuardValue()))
|
||||
.toBe(expected, urlLookup, /* an error here maybe */);
|
||||
.toBe(
|
||||
expected,
|
||||
urlLookup,
|
||||
/* an error here maybe */);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false even with UrlTree if UrlTree is lower priority', () => {
|
||||
testScheduler.run(({hot, cold, expectObservable}) => {
|
||||
|
||||
const urlTree = router.parseUrl('/');
|
||||
|
||||
const urlLookup = {U: urlTree};
|
||||
@ -111,13 +124,15 @@ describe('prioritizedGuardValue operator', () => {
|
||||
const expected = ' -------------F---';
|
||||
|
||||
expectObservable(source.pipe(prioritizedGuardValue()))
|
||||
.toBe(expected, TF, /* an error here maybe */);
|
||||
.toBe(
|
||||
expected,
|
||||
TF,
|
||||
/* an error here maybe */);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return UrlTree even after a false if the false is lower priority', () => {
|
||||
testScheduler.run(({hot, cold, expectObservable}) => {
|
||||
|
||||
const urlTree = router.parseUrl('/');
|
||||
|
||||
const urlLookup = {U: urlTree};
|
||||
@ -131,13 +146,15 @@ describe('prioritizedGuardValue operator', () => {
|
||||
const expected = ' -------------U----';
|
||||
|
||||
expectObservable(source.pipe(prioritizedGuardValue()))
|
||||
.toBe(expected, urlLookup, /* an error here maybe */);
|
||||
.toBe(
|
||||
expected,
|
||||
urlLookup,
|
||||
/* an error here maybe */);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the highest priority UrlTree', () => {
|
||||
testScheduler.run(({hot, cold, expectObservable}) => {
|
||||
|
||||
const urlTreeU = router.parseUrl('/u');
|
||||
const urlTreeR = router.parseUrl('/r');
|
||||
const urlTreeL = router.parseUrl('/l');
|
||||
@ -153,13 +170,15 @@ describe('prioritizedGuardValue operator', () => {
|
||||
const expected = ' -------------U---';
|
||||
|
||||
expectObservable(source.pipe(prioritizedGuardValue()))
|
||||
.toBe(expected, urlLookup, /* an error here maybe */);
|
||||
.toBe(
|
||||
expected,
|
||||
urlLookup,
|
||||
/* an error here maybe */);
|
||||
});
|
||||
});
|
||||
|
||||
it('should propagate errors', () => {
|
||||
testScheduler.run(({hot, cold, expectObservable}) => {
|
||||
|
||||
const a = cold(' --(T|)', TF);
|
||||
const b = cold(' ------#', TF);
|
||||
const c = cold(' ----------(F|)', TF);
|
||||
@ -168,11 +187,12 @@ describe('prioritizedGuardValue operator', () => {
|
||||
const expected = ' ---------#';
|
||||
|
||||
expectObservable(source.pipe(prioritizedGuardValue()))
|
||||
.toBe(expected, TF, /* an error here maybe */);
|
||||
.toBe(
|
||||
expected,
|
||||
TF,
|
||||
/* an error here maybe */);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user