-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(history): Reset history.current when all apps are destroyed (#3298)
* feat(history): Reset history.current when all apps are destroyed * test(history): adding restart-app test * refactor: split History.teardown method * refactor: general History.teardown method
- Loading branch information
Volodymyr Makukha
authored
Aug 31, 2020
1 parent
af6e7a0
commit c69ff7b
Showing
6 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Vue from 'vue' | ||
import VueRouter from 'vue-router' | ||
|
||
const Home = { template: '<div>home</div>' } | ||
const Foo = { template: '<div>foo</div>' } | ||
|
||
const routes = [ | ||
{ path: '/', component: Home }, | ||
{ path: '/foo', component: Foo } | ||
] | ||
|
||
const router = new VueRouter({ | ||
mode: 'history', | ||
base: __dirname, | ||
routes | ||
}) | ||
|
||
// track number of beforeResolve | ||
const increment = name => { | ||
const counter = document.getElementById(name) | ||
counter.innerHTML++ | ||
} | ||
|
||
document.getElementById('beforeEach').innerHTML = 0 | ||
router.beforeEach((to, from, next) => { | ||
increment('beforeEach') | ||
next() | ||
}) | ||
|
||
document.getElementById('beforeResolve').innerHTML = 0 | ||
router.beforeResolve((to, from, next) => { | ||
increment('beforeResolve') | ||
next() | ||
}) | ||
|
||
document.getElementById('afterEach').innerHTML = 0 | ||
router.afterEach((to, from) => { | ||
increment('afterEach') | ||
}) | ||
|
||
Vue.use(VueRouter) | ||
|
||
let vueInstance | ||
const mountEl = document.getElementById('mount') | ||
const unmountEl = document.getElementById('unmount') | ||
|
||
mountEl.addEventListener('click', () => { | ||
vueInstance = new Vue({ | ||
router, | ||
template: ` | ||
<div id="app"> | ||
<h1>Hello "Restart-app"</h1> | ||
<ul> | ||
<li><router-link to="/">Go to Home</router-link></li> | ||
<li><router-link to="/foo">Go to Foo</router-link></li> | ||
</ul> | ||
<router-view id="view"></router-view> | ||
</div> | ||
` | ||
}).$mount('#app') | ||
}) | ||
|
||
unmountEl.addEventListener('click', () => { | ||
vueInstance.$destroy() | ||
vueInstance.$el.innerHTML = '' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<link rel="stylesheet" href="/global.css"> | ||
<a href="/">← Examples index</a> | ||
|
||
<hr /> | ||
|
||
<button id="mount">mount</button> | ||
<button id="unmount">unmount</button> | ||
|
||
<hr /> | ||
|
||
Count beforeEach: <span id="beforeEach"></span><br /> | ||
Count beforeResolve: <span id="beforeResolve"></span><br /> | ||
Count afterEach: <span id="afterEach"></span><br /> | ||
|
||
<hr /> | ||
|
||
<div id="app"></div> | ||
|
||
<script src="/__build__/shared.chunk.js"></script> | ||
<script src="/__build__/restart-app.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const bsStatus = require('../browserstack-send-status') | ||
|
||
module.exports = { | ||
...bsStatus(), | ||
|
||
'@tags': ['history'], | ||
|
||
basic: function (browser) { | ||
browser | ||
.url('http://localhost:8080/restart-app/') | ||
.waitForElementVisible('#mount', 1000) | ||
.assert.containsText('#beforeEach', '0') | ||
.assert.containsText('#beforeResolve', '0') | ||
.assert.containsText('#afterEach', '0') | ||
|
||
// Mounting will trigger hooks | ||
.click('#mount') | ||
.waitForElementVisible('#app > *', 1000) | ||
.assert.containsText('#beforeEach', '1') | ||
.assert.containsText('#beforeResolve', '1') | ||
.assert.containsText('#afterEach', '1') | ||
.assert.containsText('#view', 'home') | ||
|
||
// Navigate to foo route will trigger hooks | ||
.click('#app li:nth-child(2) a') | ||
.assert.containsText('#beforeEach', '2') | ||
.assert.containsText('#beforeResolve', '2') | ||
.assert.containsText('#afterEach', '2') | ||
.assert.containsText('#view', 'foo') | ||
|
||
// Unmount | ||
.click('#unmount') | ||
.assert.containsText('#app', '') | ||
|
||
// Second mounting will trigger hooks | ||
.click('#mount') | ||
.waitForElementVisible('#app > *', 1000) | ||
.assert.containsText('#beforeEach', '3') | ||
.assert.containsText('#beforeResolve', '3') | ||
.assert.containsText('#afterEach', '3') | ||
.assert.containsText('#view', 'foo') | ||
|
||
.end() | ||
} | ||
} |