mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 11:54:02 +00:00
[new feature] Tabbar: add route prop
This commit is contained in:
90
packages/tabbar/test/index.spec.js
Normal file
90
packages/tabbar/test/index.spec.js
Normal file
@@ -0,0 +1,90 @@
|
||||
import { mount, later } from '../../../test/utils';
|
||||
import Vue from 'vue';
|
||||
import Tabbar from '..';
|
||||
import TabbarItem from '../../tabbar-item';
|
||||
|
||||
Vue.use(Tabbar);
|
||||
Vue.use(TabbarItem);
|
||||
|
||||
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 wrapper = mount({
|
||||
template: `
|
||||
<van-tabbar route>
|
||||
<van-tabbar-item replace to="/home">
|
||||
Tab
|
||||
</van-tabbar-item>
|
||||
<van-tabbar-item replace to="/search">
|
||||
Tab
|
||||
</van-tabbar-item>
|
||||
<van-tabbar-item replace :to="{ path: '/star' }">
|
||||
Tab
|
||||
</van-tabbar-item>
|
||||
<van-tabbar-item>
|
||||
Tab
|
||||
</van-tabbar-item>
|
||||
</van-tabbar>
|
||||
`
|
||||
});
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
|
||||
const items = wrapper.findAll('.van-tabbar-item');
|
||||
|
||||
items.at(1).trigger('click');
|
||||
await later();
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
|
||||
items.at(2).trigger('click');
|
||||
items.at(3).trigger('click');
|
||||
await later();
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
|
||||
test('watch tabbar value', () => {
|
||||
const wrapper = mount({
|
||||
template: `
|
||||
<van-tabbar :value="value">
|
||||
<van-tabbar-item>Tab</van-tabbar-item>
|
||||
<van-tabbar-item>Tab</van-tabbar-item>
|
||||
</van-tabbar>
|
||||
`,
|
||||
data() {
|
||||
return {
|
||||
value: 0
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.setData({ value: 1 });
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('click event', () => {
|
||||
const onClick = jest.fn();
|
||||
const onChange = jest.fn();
|
||||
|
||||
const wrapper = mount({
|
||||
template: `
|
||||
<van-tabbar @change="onChange">
|
||||
<van-tabbar-item @click="onClick">Tab</van-tabbar-item>
|
||||
</van-tabbar>
|
||||
`,
|
||||
methods: {
|
||||
onClick,
|
||||
onChange
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.find('.van-tabbar-item').trigger('click');
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
expect(onChange).toHaveBeenCalledTimes(0);
|
||||
});
|
Reference in New Issue
Block a user