-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathnative-async-test.ts
101 lines (79 loc) · 2.33 KB
/
native-async-test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Router, { Route, Transition } from 'router';
import { Dict } from 'router/core';
import { createHandler, TestRouter } from './test_helpers';
QUnit.module('native async', function (hooks) {
let router: LocalRouter;
class LocalRouter extends TestRouter {
routes: Dict<Route> = Object.create(null);
url: string | undefined;
routeDidChange() {}
routeWillChange() {}
didTransition() {}
willTransition() {}
getRoute(name: string) {
if (this.routes[name] === undefined) {
this.routes[name] = createHandler('empty');
}
return this.routes[name];
}
getSerializer(_name: string) {
return undefined;
}
replaceURL(name: string) {
this.updateURL(name);
}
updateURL(newUrl: string) {
this.url = newUrl;
}
}
hooks.beforeEach(() => {
router = new LocalRouter();
});
QUnit.test('beforeModel with returning router.transitionTo', async function (assert) {
assert.expect(3);
router.map(function (match) {
match('/').to('application', function (match) {
match('/').to('index');
match('/about').to('about');
});
});
router.routes = {
index: createHandler('index', {
beforeModel(_params: Dict<unknown>, _transition: Transition) {
assert.step('index beforeModel');
return router.transitionTo('/about');
},
}),
about: createHandler('about', {
setup() {
assert.step('about setup');
},
}),
};
await router.handleURL('/');
assert.equal(router.url, '/about', 'ended on /about');
assert.verifySteps(['index beforeModel', 'about setup']);
});
QUnit.test('async beforeModel with returning router.transitionTo', async function (assert) {
assert.expect(1);
router.map(function (match) {
match('/').to('application', function (match) {
match('/').to('index');
match('/about').to('about');
});
});
router.routes = {
index: createHandler('index', {
async beforeModel(_params: Dict<unknown>, _transition: Transition) {
return router.transitionTo('/about');
},
}),
about: createHandler('about', {
setup: function () {
assert.ok(true, 'setup was entered');
},
}),
};
await router.handleURL('/');
});
});