Skip to content

Commit 71aaf51

Browse files
authored
Merge pull request #1 from wjmao88/add-test
Add tests for named children routes using parent params
2 parents 60a5b58 + d294ede commit 71aaf51

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

examples/nested-routes/app.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ const Foo = { template: '<div>foo</div>' }
1919
const Bar = { template: '<div>bar</div>' }
2020
const Baz = { template: '<div>baz</div>' }
2121

22+
const Qux = {
23+
template: `
24+
<div class="nested-parent">
25+
<h3>qux</h3>
26+
<router-link :to="{ name: 'quux' }">/quux</router-link>
27+
<router-view class="nested-child"></router-view>
28+
</div>
29+
`
30+
}
31+
const Quux = { template: '<div>quux</div>' }
32+
2233
const router = new VueRouter({
2334
mode: 'history',
2435
base: __dirname,
@@ -40,7 +51,13 @@ const router = new VueRouter({
4051
// this allows you to leverage the component nesting without being
4152
// limited to the nested URL.
4253
// components rendered at /baz: Root -> Parent -> Baz
43-
{ path: '/baz', component: Baz }
54+
{ path: '/baz', component: Baz },
55+
56+
{
57+
path: 'qux/:quxId',
58+
component: Qux,
59+
children: [{ path: 'quux', name: 'quux', component: Quux }]
60+
}
4461
]
4562
}
4663
]
@@ -56,6 +73,7 @@ new Vue({
5673
<li><router-link to="/parent/foo">/parent/foo</router-link></li>
5774
<li><router-link to="/parent/bar">/parent/bar</router-link></li>
5875
<li><router-link to="/baz">/baz</router-link></li>
76+
<li><router-link to="/parent/qux/123">/parent/qux</router-link></li>
5977
</ul>
6078
<router-view class="view"></router-view>
6179
</div>

test/e2e/specs/nested-routes.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
browser
44
.url('http://localhost:8080/nested-routes/')
55
.waitForElementVisible('#app', 1000)
6-
.assert.count('li a', 4)
6+
.assert.count('li a', 5)
77
.assert.urlEquals('http://localhost:8080/nested-routes/parent')
88
.assert.containsText('.view', 'Parent')
99
.assert.containsText('.view', 'default')
@@ -23,6 +23,17 @@ module.exports = {
2323
.assert.containsText('.view', 'Parent')
2424
.assert.containsText('.view', 'baz')
2525

26+
.click('li:nth-child(5) a')
27+
.assert.urlEquals('http://localhost:8080/nested-routes/parent/qux/123')
28+
.assert.containsText('.view', 'Parent')
29+
.assert.containsText('.view', 'qux')
30+
31+
.click('.nested-parent a')
32+
.assert.urlEquals('http://localhost:8080/nested-routes/parent/qux/123/quux')
33+
.assert.containsText('.view', 'Parent')
34+
.assert.containsText('.view', 'qux')
35+
.assert.containsText('.view', 'quux')
36+
2637
// check initial visit
2738
.url('http://localhost:8080/nested-routes/parent/foo')
2839
.waitForElementVisible('#app', 1000)

0 commit comments

Comments
 (0)