-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersistentRouterOutlet.spec.ts
56 lines (49 loc) · 2.23 KB
/
PersistentRouterOutlet.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* tslint:disable:no-unused-variable */
import { TestBed, async, inject } from '@angular/core/testing';
import { PersistentRouterOutlet } from './PersistentRouterOutlet';
import { RouterOutletMap } from '@angular/router/src/router_outlet_map';
import { CanDeactivate, RouterOutlet, Router, Routes } from '@angular/router';
import { OpaqueToken, ComponentFactoryResolver, EventEmitter, Injector, OnDestroy, ResolvedReflectiveProvider, ViewContainerRef, NgModuleFactoryLoader, Compiler } from '@angular/core';
describe('Component: PersistentRouterOutlet', () =>
{
let persistentRouterOutlet : PersistentRouterOutlet = null;
beforeEach(() =>
{
//...use DI...
TestBed.configureTestingModule({
providers: [
PersistentRouterOutlet, //the class to be tested and...
RouterOutletMap, // it's constr arg 1
ViewContainerRef, // it's constr arg 2
ComponentFactoryResolver, // it's constr arg 3
{ provide: 'name', useValue: 'name' }, // it's constr arg 4
{ provide: Router, useValue: null } // it's constr arg 5 useValue/useClass
]
});
//...or create object to be tested manually
persistentRouterOutlet = new PersistentRouterOutlet(new RouterOutletMap(), null, null, null, null);
});
//test class with DI-created object
it('should inject a _persistentRouterOutlet instance',
inject([PersistentRouterOutlet], (_persistentRouterOutlet: PersistentRouterOutlet) =>
{
expect(_persistentRouterOutlet).toBeTruthy();
}));
//test class with the manually created object
it('should create a persistentRouterOutlet instance', () =>
{
expect(persistentRouterOutlet).toBeTruthy();
});
it('should not cache complicated urls', () =>
{
let url:string = "/complicated/Url?param=12";
let isCacheable:boolean = persistentRouterOutlet.isCacheable(url);
expect(isCacheable).toEqual(false);
});
it('should cache simple urls', () =>
{
let url:string = "search";
let isCacheable:boolean = persistentRouterOutlet.isCacheable(url);
expect(isCacheable).toEqual(true);
});
});