mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 03:11:15 +00:00
[bugfix] Tabbar: avoid navigation duplicated (#4147)
This commit is contained in:
@@ -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');
|
||||
});
|
||||
|
Reference in New Issue
Block a user