feat(Tabs): add click-tab event (#9037)
This commit is contained in:
@@ -146,32 +146,6 @@ test('border props', async () => {
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('click event', async () => {
|
||||
const onClick = jest.fn();
|
||||
const onDisabled = jest.fn();
|
||||
|
||||
const wrapper = mount({
|
||||
template: `
|
||||
<van-tabs @click="onClick" @disabled="onDisabled">
|
||||
<van-tab title="title1">Text</van-tab>
|
||||
<van-tab title="title2" disabled>Text</van-tab>
|
||||
</van-tabs>
|
||||
`,
|
||||
methods: {
|
||||
onClick,
|
||||
onDisabled,
|
||||
},
|
||||
});
|
||||
|
||||
const tabs = wrapper.findAll('.van-tab');
|
||||
|
||||
tabs[0].trigger('click');
|
||||
expect(onClick).toHaveBeenCalledWith(0, 'title1');
|
||||
|
||||
tabs[1].trigger('click');
|
||||
expect(onDisabled).toHaveBeenCalledWith(1, 'title2');
|
||||
});
|
||||
|
||||
test('name prop', async () => {
|
||||
const onClick = jest.fn();
|
||||
const onChange = jest.fn();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { mount, later } from '../../../test';
|
||||
import { Tab } from '..';
|
||||
import { Tabs } from '../../tabs';
|
||||
|
||||
test('should emit click event when tab is clicked', async () => {
|
||||
const onClick = jest.fn();
|
||||
|
||||
const wrapper = mount({
|
||||
render() {
|
||||
return (
|
||||
<Tabs onClick={onClick}>
|
||||
<Tab title="title1">1</Tab>
|
||||
<Tab title="title2">2</Tab>
|
||||
</Tabs>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
const tabs = wrapper.findAll('.van-tab');
|
||||
|
||||
await tabs[0].trigger('click');
|
||||
expect(onClick).toHaveBeenCalledWith(0, 'title1');
|
||||
});
|
||||
|
||||
test('should emit click-tab event when tab is clicked', async () => {
|
||||
const onClickTab = jest.fn();
|
||||
|
||||
const wrapper = mount({
|
||||
render() {
|
||||
return (
|
||||
<Tabs onClick-tab={onClickTab}>
|
||||
<Tab title="title1">1</Tab>
|
||||
<Tab title="title2">2</Tab>
|
||||
</Tabs>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
const tabs = wrapper.findAll('.van-tab');
|
||||
|
||||
await tabs[0].trigger('click');
|
||||
expect(onClickTab).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
name: 0,
|
||||
title: 'title1',
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user