Skip to content

Commit ddd864f

Browse files
committed
test: add e2e test for onSuccess callback
1 parent 4fbcd5e commit ddd864f

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

examples/basic/app.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const router = new VueRouter({
2929
// Route components will be rendered inside <router-view>.
3030
new Vue({
3131
router,
32+
data: () => ({ n: 0 }),
3233
template: `
3334
<div id="app">
3435
<h1>Basic</h1>
@@ -43,9 +44,22 @@ new Vue({
4344
<li><router-link to="/é?t=%25ñ">/é?t=%ñ</router-link></li>
4445
<li><router-link to="/é#%25ñ">/é#%25ñ</router-link></li>
4546
</ul>
47+
<button id="navigate-btn" @click="navigateAndIncrement">On Success</button>
48+
<pre id="counter">{{ n }}</pre>
4649
<pre id="query-t">{{ $route.query.t }}</pre>
4750
<pre id="hash">{{ $route.hash }}</pre>
4851
<router-view class="view"></router-view>
4952
</div>
50-
`
53+
`,
54+
55+
methods: {
56+
navigateAndIncrement () {
57+
const increment = () => this.n++
58+
if (this.$route.path === '/') {
59+
this.$router.push('/foo', increment)
60+
} else {
61+
this.$router.push('/', increment)
62+
}
63+
}
64+
}
5165
}).$mount('#app')

src/util/resolve-components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function resolveAsyncComponents (matched: Array<RouteRecord>): Function {
3030
match.components[key] = resolvedDef
3131
pending--
3232
if (pending <= 0) {
33-
next()
33+
next(to)
3434
}
3535
})
3636

test/e2e/specs/basic.js

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ module.exports = {
4040
.url('http://localhost:8080/basic/%C3%A9')
4141
.waitForElementVisible('#app', 1000)
4242
.assert.containsText('.view', 'unicode')
43+
44+
// regression onComplete
45+
// https://github.com/vuejs/vue-router/issues/2721
46+
.assert.containsText('#counter', '0')
47+
.click('#navigate-btn')
48+
.assert.containsText('#counter', '1')
49+
.click('#navigate-btn')
50+
.assert.containsText('#counter', '2')
51+
4352
.end()
4453
}
4554
}

0 commit comments

Comments
 (0)