feat(Tab): add scrollTo method (#6800)

This commit is contained in:
neverland
2020-07-16 22:48:26 +08:00
committed by GitHub
parent 76c2f5efda
commit b249c690d7
6 changed files with 44 additions and 8 deletions
+25 -1
View File
@@ -258,7 +258,7 @@ test('info prop', () => {
expect(wrapper).toMatchSnapshot();
});
test('scrollspy', async () => {
test('scrollspy prop', async () => {
const onChange = jest.fn();
window.scrollTo = jest.fn();
@@ -288,6 +288,30 @@ test('scrollspy', async () => {
expect(onChange).toHaveBeenCalledWith('c', 'title3');
});
test('scrollTo method', async () => {
const onChange = jest.fn();
window.scrollTo = jest.fn();
mount({
template: `
<van-tabs scrollspy sticky @change="onChange" ref="root">
<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,
},
mounted() {
this.$refs.root.scrollTo('b');
},
});
await later();
expect(onChange).toHaveBeenCalledWith('b', 'title2');
});
test('rendered event', async () => {
const onRendered = jest.fn();