-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathns-router-link.spec.ts
More file actions
61 lines (56 loc) · 2.11 KB
/
Copy pathns-router-link.spec.ts
File metadata and controls
61 lines (56 loc) · 2.11 KB
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
57
58
59
60
61
import { NSRouterLink, NativeScriptRouterModule } from '@nativescript/angular';
import { RouterExtensions } from '@nativescript/angular';
import { fake } from './test-config.spec';
import { Component, ViewChild } from '@angular/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NativeScriptModule } from '@nativescript/angular';
@Component({
imports: [NativeScriptRouterModule, NSRouterLink],
template: `<Label nsRouterLink="/test" text="Test"></Label>`,
})
class RouterLinkTestComponent {
@ViewChild(NSRouterLink, { static: false }) nsRouterLink: NSRouterLink;
}
describe('NSRouterLink', () => {
let mockNavigate: ReturnType<typeof fake>;
let fixture: ComponentFixture<RouterLinkTestComponent>;
beforeEach(async () => {
mockNavigate = fake();
TestBed.configureTestingModule({
imports: [
NativeScriptModule,
NativeScriptRouterModule.forRoot([{ path: 'test', component: RouterLinkTestComponent }]),
RouterLinkTestComponent,
],
providers: [
{
provide: RouterExtensions,
useValue: {
navigateByUrl: fake(),
navigate: mockNavigate,
},
},
],
});
await TestBed.compileComponents();
fixture = TestBed.createComponent(RouterLinkTestComponent);
fixture.detectChanges();
await fixture.whenStable();
});
it('#tap should call navigate with undefined transition in extras when boolean is given for pageTransition input', () => {
const directive = fixture.componentInstance.nsRouterLink;
directive.pageTransition = false;
directive['onTap']();
expect(mockNavigate.lastCall.args[1].transition).toBeUndefined();
});
it('#tap should call navigate with correct transition in extras when NavigationTransition object is given for pageTransition input', () => {
const pageTransition = {
name: 'slide',
duration: 500,
};
const directive = fixture.componentInstance.nsRouterLink;
directive.pageTransition = pageTransition;
directive['onTap']();
expect(mockNavigate.lastCall.args[1].transition).toBe(pageTransition);
});
});