Skip to content

Commit

Permalink
[bugfix] Tab: click event param missing (#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jul 16, 2019
1 parent aba5f59 commit a594774
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/tab/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/tabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},

Expand Down

0 comments on commit a594774

Please sign in to comment.