Skip to content

Commit d20b645

Browse files
committed
fix(router): fix return value for getTransition of NSRouterLink
Return undefined transition value from getTransition method of NSRouterLink when boolean value is used for pageTransition input. Closes #1784
1 parent d4739f5 commit d20b645

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

Diff for: nativescript-angular/router/ns-router-link.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class NSRouterLink { // tslint:disable-line:directive-class-suffix
115115
}
116116

117117
private getTransition(): { animated: boolean, transition?: NavigationTransition } {
118-
let transition: NavigationTransition = {};
118+
let transition: NavigationTransition;
119119
let animated: boolean;
120120

121121
if (typeof this.pageTransition === "boolean") {
@@ -125,7 +125,9 @@ export class NSRouterLink { // tslint:disable-line:directive-class-suffix
125125
animated = false;
126126
} else {
127127
animated = true;
128-
transition.name = <string>this.pageTransition;
128+
transition = {
129+
name: <string>this.pageTransition
130+
};
129131
}
130132
} else {
131133
animated = true;
@@ -134,6 +136,7 @@ export class NSRouterLink { // tslint:disable-line:directive-class-suffix
134136

135137
let duration = +this.pageTransitionDuration;
136138
if (!isNaN(duration)) {
139+
transition = transition || {};
137140
transition.duration = duration;
138141
}
139142

Diff for: tests/app/tests/ns-router-link.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {NSRouterLink} from "nativescript-angular/router/ns-router-link";
2+
import {ActivatedRoute, Router} from "@angular/router";
3+
import {RouterExtensions} from "nativescript-angular/router";
4+
import {assert, fake, spy, stub} from "./test-config";
5+
import {SinonStub} from "sinon";
6+
7+
describe("NSRouterLink", () => {
8+
9+
const mockRouter = {} as Router;
10+
let mockRouterExtensions = {
11+
navigateByUrl: fake()
12+
};
13+
const mockActivatedRoute = {} as ActivatedRoute;
14+
let nsRouterLink: NSRouterLink;
15+
let urlTreeStub: SinonStub;
16+
17+
beforeEach(() => {
18+
nsRouterLink = new NSRouterLink(mockRouter, mockRouterExtensions as unknown as RouterExtensions, mockActivatedRoute);
19+
urlTreeStub = stub(nsRouterLink, 'urlTree').get(() => null);
20+
});
21+
22+
afterEach(() => {
23+
urlTreeStub.restore();
24+
});
25+
26+
it('#tap should call navigateByUrl with undefined transition in extras when boolean is given for pageTransition input', () => {
27+
nsRouterLink.pageTransition = false;
28+
nsRouterLink.onTap();
29+
assert.isUndefined(mockRouterExtensions.navigateByUrl.lastCall.args[1].transition);
30+
});
31+
32+
it('#tap should call navigateByUrl with correct transition in extras when NavigationTransition object is given for pageTransition input', () => {
33+
const pageTransition = {
34+
name: 'slide',
35+
duration: 500
36+
};
37+
nsRouterLink.pageTransition = pageTransition;
38+
stub(nsRouterLink, 'urlTree').get(() => null);
39+
nsRouterLink.onTap();
40+
assert.equal(pageTransition, mockRouterExtensions.navigateByUrl.lastCall.args[1].transition);
41+
});
42+
43+
});

Diff for: tests/app/tests/test-config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
});
44

55
import * as chai from "chai";
6+
import * as sinon from "sinon";
67
export let assert: typeof chai.assert = (<any>global).chai.assert;
8+
export let fake: typeof sinon.fake = (<any>global).sinon.fake;
9+
export let spy: typeof sinon.spy = (<any>global).sinon.spy;
10+
export let stub: typeof sinon.stub = (<any>global).sinon.stub;

Diff for: tests/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function(config) {
88

99
// frameworks to use
1010
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
11-
frameworks: ['mocha', 'chai'],
11+
frameworks: ['mocha', 'chai', 'sinon'],
1212

1313

1414
// list of files / patterns to load in the browser

Diff for: tests/package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,21 @@
4444
"devDependencies": {
4545
"@types/chai": "^4.1.4",
4646
"@types/mocha": "^5.2.4",
47+
"@types/sinon": "^7.0.11",
48+
"babel-traverse": "6.8.0",
49+
"babel-types": "6.8.1",
50+
"babylon": "6.8.0",
4751
"chai": "4.1.2",
4852
"karma": "2.0.4",
4953
"karma-chai": "0.1.0",
5054
"karma-mocha": "1.3.0",
5155
"karma-mocha-reporter": "2.2.5",
5256
"karma-nativescript-launcher": "0.4.0",
57+
"karma-sinon": "^1.0.5",
58+
"lazy": "1.0.11",
5359
"mocha": "5.2.0",
5460
"nativescript-dev-typescript": "next",
55-
"babel-traverse": "6.8.0",
56-
"babel-types": "6.8.1",
57-
"babylon": "6.8.0",
58-
"lazy": "1.0.11",
61+
"sinon": "^7.3.2",
5962
"tslint": "^4.5.1",
6063
"typescript": "~3.1.1"
6164
},

0 commit comments

Comments
 (0)