fix(Tab): can't match when name is 0 (#5017)

This commit is contained in:
neverland 2019-11-14 20:10:22 +08:00 committed by GitHub
parent 5d157c409b
commit d068286562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { createNamespace } from '../utils';
import { isDef, createNamespace } from '../utils';
import { ChildrenMixin } from '../mixins/relation';
import { routeProps } from '../utils/router';
@ -22,7 +22,7 @@ export default createComponent({
computed: {
computedName() {
return this.name || this.index;
return isDef(this.name) ? this.name : this.index;
},
isActive() {

View File

@ -173,7 +173,6 @@ test('click event', async () => {
expect(onDisabled).toHaveBeenCalledWith(1, 'title2');
});
test('name prop', async () => {
const onClick = jest.fn();
const onChange = jest.fn();
@ -208,3 +207,23 @@ test('name prop', async () => {
expect(onDisabled).toHaveBeenCalledWith('c', 'title3');
expect(onChange).toHaveBeenCalledTimes(1);
});
test('set name to zero', async () => {
const onClick = jest.fn();
const wrapper = mount({
template: `
<van-tabs @click="onClick">
<van-tab title="title1" :name="1">Text</van-tab>
<van-tab title="title2" :name="0">Text</van-tab>
</van-tabs>
`,
methods: {
onClick
}
});
const tabs = wrapper.findAll('.van-tab');
tabs.at(1).trigger('click');
expect(onClick).toHaveBeenCalledWith(0, 'title2');
});