mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Tab): can't match when name is 0 (#5017)
This commit is contained in:
parent
5d157c409b
commit
d068286562
@ -1,4 +1,4 @@
|
|||||||
import { createNamespace } from '../utils';
|
import { isDef, createNamespace } from '../utils';
|
||||||
import { ChildrenMixin } from '../mixins/relation';
|
import { ChildrenMixin } from '../mixins/relation';
|
||||||
import { routeProps } from '../utils/router';
|
import { routeProps } from '../utils/router';
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ export default createComponent({
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
computedName() {
|
computedName() {
|
||||||
return this.name || this.index;
|
return isDef(this.name) ? this.name : this.index;
|
||||||
},
|
},
|
||||||
|
|
||||||
isActive() {
|
isActive() {
|
||||||
|
@ -173,7 +173,6 @@ test('click event', async () => {
|
|||||||
expect(onDisabled).toHaveBeenCalledWith(1, 'title2');
|
expect(onDisabled).toHaveBeenCalledWith(1, 'title2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('name prop', async () => {
|
test('name prop', async () => {
|
||||||
const onClick = jest.fn();
|
const onClick = jest.fn();
|
||||||
const onChange = jest.fn();
|
const onChange = jest.fn();
|
||||||
@ -208,3 +207,23 @@ test('name prop', async () => {
|
|||||||
expect(onDisabled).toHaveBeenCalledWith('c', 'title3');
|
expect(onDisabled).toHaveBeenCalledWith('c', 'title3');
|
||||||
expect(onChange).toHaveBeenCalledTimes(1);
|
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');
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user