diff --git a/src/tab/test/index.spec.js b/src/tab/test/index.spec.js index 874d64be2..313ec8494 100644 --- a/src/tab/test/index.spec.js +++ b/src/tab/test/index.spec.js @@ -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: ` + + Text + Text + + `, + 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(); diff --git a/src/tabs/index.js b/src/tabs/index.js index 9f66ad433..7f54788e0 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -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); } },