Skip to content

Commit eb5e80f

Browse files
Kevin Smithsonposva
Kevin Smithson
authored andcommitted
added some route-matching tests
1 parent 6162453 commit eb5e80f

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

examples/route-matching/app.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ const router = new VueRouter({
2121
// asterisk can match anything
2222
{ path: '/asterisk/*' },
2323
// make part of the path optional by wrapping with parens and add "?"
24-
{ path: '/optional-group/(foo/)?bar' }
24+
{ path: '/optional-group/(foo/)?bar' },
25+
26+
// caseSensitive match
27+
{ path: '/FooBar', caseSensitive: true },
28+
{ path: '/FOOBar', pathToRegexpOptions: { sensitive: true }},
29+
// Not case sensitive (which is default)
30+
{ path: '/foo', caseSensitive: false },
31+
{ path: '/FOO', caseSensitive: false } // Should match /foo
2532
]
2633
})
2734

@@ -41,6 +48,10 @@ new Vue({
4148
<li><router-link to="/asterisk/foo/bar">/asterisk/foo/bar</router-link></li>
4249
<li><router-link to="/optional-group/bar">/optional-group/bar</router-link></li>
4350
<li><router-link to="/optional-group/foo/bar">/optional-group/foo/bar</router-link></li>
51+
<li><router-link to="/FooBar">/FooBar</router-link></li>
52+
<li><router-link to="/FOOBar">/FOOBar</router-link></li>
53+
<li><router-link to="/foo">/foo</router-link></li>
54+
<li><router-link to="/FOO">/FOO</router-link></li>
4455
</ul>
4556
<p>Route context</p>
4657
<pre>{{ JSON.stringify($route, null, 2) }}</pre>

test/e2e/specs/route-matching.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
browser
44
.url('http://localhost:8080/route-matching/')
55
.waitForElementVisible('#app', 1000)
6-
.assert.count('li a', 10)
6+
.assert.count('li a', 14)
77
.assert.evaluate(function () {
88
var route = JSON.parse(document.querySelector('pre').textContent)
99
return (
@@ -125,6 +125,53 @@ module.exports = {
125125
)
126126
}, null, '/optional-group/foo/bar')
127127

128+
.click('li:nth-child(11) a')
129+
.assert.evaluate(function () {
130+
var route = JSON.parse(document.querySelector('pre').textContent)
131+
return (
132+
route.matched.length === 1 &&
133+
route.matched[0].path === '/FooBar' &&
134+
route.fullPath === '/FooBar' &&
135+
JSON.stringify(route.params) === JSON.stringify({}) &&
136+
route.matched[0].pathToRegexpOptions.sensitive === true
137+
)
138+
}, null, '/FooBar')
139+
140+
.click('li:nth-child(12) a')
141+
.assert.evaluate(function () {
142+
var route = JSON.parse(document.querySelector('pre').textContent)
143+
return (
144+
route.matched.length === 1 &&
145+
route.matched[0].path === '/FOOBar' &&
146+
route.fullPath === '/FOOBar' &&
147+
JSON.stringify(route.params) === JSON.stringify({}) &&
148+
route.matched[0].pathToRegexpOptions.sensitive === true
149+
)
150+
}, null, '/FOOBar')
151+
152+
.click('li:nth-child(13) a')
153+
.assert.evaluate(function () {
154+
var route = JSON.parse(document.querySelector('pre').textContent)
155+
return (
156+
route.matched.length === 1 &&
157+
route.matched[0].path === '/foo' &&
158+
route.fullPath === '/foo' &&
159+
JSON.stringify(route.params) === JSON.stringify({}) &&
160+
route.matched[0].pathToRegexpOptions.sensitive === false
161+
)
162+
}, null, '/foo')
163+
164+
.click('li:nth-child(14) a')
165+
.assert.evaluate(function () {
166+
var route = JSON.parse(document.querySelector('pre').textContent)
167+
return (
168+
route.matched.length === 1 &&
169+
route.matched[0].path === '/foo' &&
170+
route.fullPath === '/FOO' &&
171+
JSON.stringify(route.params) === JSON.stringify({}) &&
172+
route.matched[0].pathToRegexpOptions.sensitive === false
173+
)
174+
}, null, '/FOOBar')
128175
.end()
129176
}
130177
}

0 commit comments

Comments
 (0)