Skip to content

Commit 885ac18

Browse files
committed
add route-matching test case
1 parent 8fbaf9e commit 885ac18

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

test/e2e/specs/route-matching.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
module.exports = {
2+
'route-matching': function (browser) {
3+
browser
4+
.url('http://localhost:8080/route-matching/')
5+
.waitForElementVisible('#app', 1000)
6+
.assert.count('li a', 10)
7+
.assert.evaluate(function () {
8+
var route = JSON.parse(document.querySelector('pre').textContent)
9+
return (
10+
route.matched.length === 1 &&
11+
route.matched[0].path === '' &&
12+
route.fullPath === '/' &&
13+
JSON.stringify(route.params) === JSON.stringify({})
14+
)
15+
}, null, '/')
16+
17+
.click('li:nth-child(2) a')
18+
.assert.evaluate(function () {
19+
var route = JSON.parse(document.querySelector('pre').textContent)
20+
return (
21+
route.matched.length === 1 &&
22+
route.matched[0].path === '/params/:foo/:bar' &&
23+
route.fullPath === '/params/foo/bar' &&
24+
JSON.stringify(route.params) === JSON.stringify({
25+
foo: 'foo',
26+
bar: 'bar'
27+
})
28+
)
29+
}, null, '/params/foo/bar')
30+
31+
.click('li:nth-child(3) a')
32+
.assert.evaluate(function () {
33+
var route = JSON.parse(document.querySelector('pre').textContent)
34+
return (
35+
route.matched.length === 1 &&
36+
route.matched[0].path === '/optional-params/:foo?' &&
37+
route.fullPath === '/optional-params' &&
38+
JSON.stringify(route.params) === JSON.stringify({})
39+
)
40+
}, null, '/optional-params')
41+
42+
.click('li:nth-child(4) a')
43+
.assert.evaluate(function () {
44+
var route = JSON.parse(document.querySelector('pre').textContent)
45+
return (
46+
route.matched.length === 1 &&
47+
route.matched[0].path === '/optional-params/:foo?' &&
48+
route.fullPath === '/optional-params/foo' &&
49+
JSON.stringify(route.params) === JSON.stringify({
50+
foo: 'foo'
51+
})
52+
)
53+
}, null, '/optional-params/foo')
54+
55+
.click('li:nth-child(5) a')
56+
.assert.evaluate(function () {
57+
var route = JSON.parse(document.querySelector('pre').textContent)
58+
return (
59+
route.matched.length === 1 &&
60+
route.matched[0].path === '/params-with-regex/:id(\\d+)' &&
61+
route.fullPath === '/params-with-regex/123' &&
62+
JSON.stringify(route.params) === JSON.stringify({
63+
id: '123'
64+
})
65+
)
66+
}, null, '/params-with-regex/123')
67+
68+
.click('li:nth-child(6) a')
69+
.assert.evaluate(function () {
70+
var route = JSON.parse(document.querySelector('pre').textContent)
71+
return (
72+
route.matched.length === 0 &&
73+
route.fullPath === '/params-with-regex/abc' &&
74+
JSON.stringify(route.params) === JSON.stringify({})
75+
)
76+
}, null, '/params-with-regex/abc')
77+
78+
.click('li:nth-child(7) a')
79+
.assert.evaluate(function () {
80+
var route = JSON.parse(document.querySelector('pre').textContent)
81+
return (
82+
route.matched.length === 1 &&
83+
route.matched[0].path === '/asterisk/*' &&
84+
route.fullPath === '/asterisk/foo' &&
85+
JSON.stringify(route.params) === JSON.stringify({
86+
0: 'foo'
87+
})
88+
)
89+
}, null, '/asterisk/foo')
90+
91+
.click('li:nth-child(8) a')
92+
.assert.evaluate(function () {
93+
var route = JSON.parse(document.querySelector('pre').textContent)
94+
return (
95+
route.matched.length === 1 &&
96+
route.matched[0].path === '/asterisk/*' &&
97+
route.fullPath === '/asterisk/foo/bar' &&
98+
JSON.stringify(route.params) === JSON.stringify({
99+
0: 'foo/bar'
100+
})
101+
)
102+
}, null, '/asterisk/foo/bar')
103+
104+
.click('li:nth-child(9) a')
105+
.assert.evaluate(function () {
106+
var route = JSON.parse(document.querySelector('pre').textContent)
107+
return (
108+
route.matched.length === 1 &&
109+
route.matched[0].path === '/optional-group/(foo/)?bar' &&
110+
route.fullPath === '/optional-group/bar' &&
111+
JSON.stringify(route.params) === JSON.stringify({})
112+
)
113+
}, null, '/optional-group/bar')
114+
115+
.click('li:nth-child(10) a')
116+
.assert.evaluate(function () {
117+
var route = JSON.parse(document.querySelector('pre').textContent)
118+
return (
119+
route.matched.length === 1 &&
120+
route.matched[0].path === '/optional-group/(foo/)?bar' &&
121+
route.fullPath === '/optional-group/foo/bar' &&
122+
JSON.stringify(route.params) === JSON.stringify({
123+
0: 'foo/'
124+
})
125+
)
126+
}, null, '/optional-group/foo/bar')
127+
128+
.end()
129+
}
130+
}

0 commit comments

Comments
 (0)