Skip to content

Commit

Permalink
chore(test): added coverage for out-in transition before route enter cb
Browse files Browse the repository at this point in the history
  • Loading branch information
ronald-d-rogers committed Aug 10, 2019
1 parent ecd71e7 commit f340981
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
47 changes: 34 additions & 13 deletions examples/navigation-guards/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,25 @@ const Quux = {
}

const NestedParent = {
template: `<div id="nested-parent">Nested Parent <hr>
<router-link to="/parent/child/1">/parent/child/1</router-link>
<router-link to="/parent/child/2">/parent/child/2</router-link>
<hr>
<p id="bre-order">
<span v-for="log in logs">{{ log }} </span>
</p>
<router-view/></div>`,
template: `
<div id="nested-parent">
Nested Parent
<hr>
<router-link to="/parent/child/1">/parent/child/1</router-link>
<router-link to="/parent/child/2">/parent/child/2</router-link>
<hr>
<p id="bre-order">
<span v-for="log in logs">{{ log }} </span>
</p>
<!-- #705 -->
<!-- Some transitions, specifically out-in transitions, cause the view -->
<!-- that is transitioning in to appear significantly later than normal, -->
<!-- which can cause bugs as "vm" below in "next(vm => ...)" may not be -->
<!-- available at the time the callback is called -->
<transition name="fade" mode="out-in">
<router-view/>
</transition>
</div>`,
data: () => ({ logs: [] }),
beforeRouteEnter (to, from, next) {
next(vm => {
Expand All @@ -116,7 +126,18 @@ const GuardMixin = {
}
}

const NestedChild = {
const NestedChild1 = {
props: ['n'],
template: `<div>Child {{ n }}</div>`,
mixins: [GuardMixin],
beforeRouteEnter (to, from, next) {
next(vm => {
vm.$parent.logs.push('child ' + vm.n)
})
}
}

const NestedChild2 = {
props: ['n'],
template: `<div>Child {{ n }}</div>`,
mixins: [GuardMixin],
Expand Down Expand Up @@ -162,10 +183,10 @@ const router = new VueRouter({
path: '/parent',
component: NestedParent,
children: [
{ path: 'child/1', component: NestedChild, props: { n: 1 }},
{ path: 'child/2', component: NestedChild, props: { n: 2 }}
{ path: 'child/1', component: NestedChild1, props: { n: 1 }},
{ path: 'child/2', component: NestedChild2, props: { n: 2 }}
]
}
},
]
})

Expand Down
8 changes: 8 additions & 0 deletions examples/navigation-guards/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<!DOCTYPE html>
<link rel="stylesheet" href="/global.css">
<style>
.fade-enter-active, .fade-leave-active {
transition: opacity .5s ease;
}
.fade-enter, .fade-leave-active {
opacity: 0;
}
</style>
<a href="/">&larr; Examples index</a>
<div id="app"></div>
<script src="/__build__/shared.chunk.js"></script>
Expand Down

0 comments on commit f340981

Please sign in to comment.