From d068286562c0fe0998ee408e5fffb4310a11d033 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 14 Nov 2019 20:10:22 +0800 Subject: [PATCH] fix(Tab): can't match when name is 0 (#5017) --- src/tab/index.js | 4 ++-- src/tab/test/index.spec.js | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/tab/index.js b/src/tab/index.js index 2b3852d83..15996025d 100644 --- a/src/tab/index.js +++ b/src/tab/index.js @@ -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() { diff --git a/src/tab/test/index.spec.js b/src/tab/test/index.spec.js index 9bac4bede..978918526 100644 --- a/src/tab/test/index.spec.js +++ b/src/tab/test/index.spec.js @@ -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: ` + + Text + Text + + `, + methods: { + onClick + } + }); + + const tabs = wrapper.findAll('.van-tab'); + tabs.at(1).trigger('click'); + expect(onClick).toHaveBeenCalledWith(0, 'title2'); +});