[bugfix] Tabbar: avoid navigation duplicated (#4147)

This commit is contained in:
neverland
2019-08-19 11:04:25 +08:00
committed by GitHub
parent 1d673ca898
commit 4e828fbc70
4 changed files with 49 additions and 18 deletions

View File

@@ -1,3 +1,4 @@
import VueRouter from 'vue-router';
import { mount, later } from '../../../test/utils';
import Vue from 'vue';
import Tabbar from '..';
@@ -5,20 +6,15 @@ import TabbarItem from '../../tabbar-item';
Vue.use(Tabbar);
Vue.use(TabbarItem);
Vue.use(VueRouter);
test('route mode', async () => {
Vue.util.defineReactive(Vue.prototype, '$route', { path: '/home' });
Vue.prototype.$router = {
replace(to) {
Vue.prototype.$route.path = typeof to === 'string' ? to : to.path;
}
};
const router = new VueRouter();
const wrapper = mount({
router,
template: `
<van-tabbar route>
<van-tabbar-item replace to="/home">
<van-tabbar-item replace to="/">
Tab
</van-tabbar-item>
<van-tabbar-item replace to="/search">
@@ -48,6 +44,28 @@ test('route mode', async () => {
expect(wrapper).toMatchSnapshot();
});
test('router NavigationDuplicated', async done => {
expect(async () => {
const router = new VueRouter();
const wrapper = mount({
router,
template: `
<van-tabbar route>
<van-tabbar-item replace to="/home">
Tab
</van-tabbar-item>
</van-tabbar>
`
});
const item = wrapper.find('.van-tabbar-item');
item.trigger('click');
item.trigger('click');
await later();
done();
}).not.toThrow();
});
test('watch tabbar value', () => {
const wrapper = mount({
@@ -108,7 +126,10 @@ test('name prop', () => {
}
});
wrapper.findAll('.van-tabbar-item').at(1).trigger('click');
wrapper
.findAll('.van-tabbar-item')
.at(1)
.trigger('click');
expect(onChange).toHaveBeenCalledWith('b');
});