[bugfix] Tab: click event param missing (#3866)

This commit is contained in:
neverland 2019-07-16 17:13:05 +08:00 committed by GitHub
parent aba5f59fdd
commit a594774ee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -146,6 +146,34 @@ test('border props', async () => {
expect(wrapper).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.at(0).trigger('click');
expect(onClick).toHaveBeenCalledWith(0, 'title1');
tabs.at(1).trigger('click');
expect(onDisabled).toHaveBeenCalledWith(1, 'title2');
});
test('name prop', async () => {
const onClick = jest.fn();
const onChange = jest.fn();

View File

@ -276,12 +276,12 @@ export default createComponent({
// emit event when clicked
onClick(index) {
const { title, disabled, name } = this.children[index];
const { title, disabled, computedName } = this.children[index];
if (disabled) {
this.$emit('disabled', name, title);
this.$emit('disabled', computedName, title);
} else {
this.setCurrentIndex(index);
this.$emit('click', name, title);
this.$emit('click', computedName, title);
}
},