feat(Tab): add scrollspy prop (#5273)

This commit is contained in:
健忘症患者丶
2019-12-16 20:17:09 +08:00
committed by neverland
parent 9cd06f3b20
commit 4603e1633c
12 changed files with 266 additions and 10 deletions
+31 -1
View File
@@ -1,7 +1,7 @@
import Vue from 'vue';
import Tab from '..';
import Tabs from '../../tabs';
import { mount, later, triggerDrag } from '../../../test';
import { mount, later, triggerDrag, mockScrollTop } from '../../../test';
Vue.use(Tab);
Vue.use(Tabs);
@@ -263,3 +263,33 @@ test('info prop', () => {
expect(wrapper).toMatchSnapshot();
});
test('scrollspy', async () => {
const onChange = jest.fn();
window.scrollTo = jest.fn();
const wrapper = mount({
template: `
<van-tabs scrollspy sticky @change="onChange">
<van-tab name="a" title="title1">Text</van-tab>
<van-tab name="b" title="title2">Text</van-tab>
<van-tab name="c" title="title3">Text</van-tab>
</van-tabs>
`,
methods: {
onChange
}
});
await later();
expect(wrapper).toMatchSnapshot();
const tabs = wrapper.findAll('.van-tab');
tabs.at(2).trigger('click');
expect(onChange).toHaveBeenCalledWith('c', 'title3');
await later();
mockScrollTop(100);
expect(wrapper).toMatchSnapshot();
expect(onChange).toHaveBeenCalledWith('c', 'title3');
});