test(Tag): update test cases

This commit is contained in:
chenjiahan 2020-11-14 14:51:04 +08:00
parent 9bd38cf446
commit 3093ee1d84
4 changed files with 48 additions and 57 deletions

View File

@ -98,14 +98,14 @@ export default {
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| type | 类型,可选值为`primary` `success` `danger` `warning` | _string_ | `default` |
| size | 大小, 可选值为`large` `medium` | _string_ | - |
| type | 类型,可选值为 `primary` `success` `danger` `warning` | _string_ | `default` |
| size | 大小, 可选值为 `large` `medium` | _string_ | - |
| color | 标签颜色 | _string_ | - |
| show | 是否展示标签 | _boolean_ | `true` |
| plain | 是否为空心样式 | _boolean_ | `false` |
| round | 是否为圆角样式 | _boolean_ | `false` |
| mark | 是否为标记样式 | _boolean_ | `false` |
| text-color | 文本颜色,优先级高于`color`属性 | _string_ | `white` |
| text-color | 文本颜色,优先级高于 `color` 属性 | _string_ | `white` |
| closeable | 是否为可关闭标签 | _boolean_ | `false` |
### Slots

View File

@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`should hide tag when the show prop is false 1`] = `
<transition-stub>
<!---->
</transition-stub>
`;

View File

@ -1,54 +0,0 @@
import Tag from '..';
import { mount } from '@vue/test-utils';
test('click event', () => {
const click = jest.fn();
const wrapper = mount(Tag, {
context: {
on: {
click,
},
},
});
wrapper.trigger('click');
expect(click).toHaveBeenCalledTimes(1);
});
test('close event', () => {
const close = jest.fn();
const wrapper = mount(Tag, {
props: {
closeable: true,
},
context: {
on: {
close,
},
},
});
wrapper.find('.van-tag__close').trigger('click');
expect(close).toHaveBeenCalledTimes(1);
});
test('should not trigger click event when close', () => {
const close = jest.fn();
const click = jest.fn();
const wrapper = mount(Tag, {
props: {
closeable: true,
},
context: {
on: {
close,
click,
},
},
});
wrapper.find('.van-tag__close').trigger('click');
expect(close).toHaveBeenCalledTimes(1);
expect(click).toHaveBeenCalledTimes(0);
});

View File

@ -0,0 +1,38 @@
import Tag from '..';
import { mount } from '@vue/test-utils';
test('should emit close event when clicking the close icon', () => {
const wrapper = mount(Tag, {
props: {
closeable: true,
},
});
wrapper.find('.van-tag__close').trigger('click');
expect(wrapper.emitted('close').length).toEqual(1);
});
test('should hide tag when the show prop is false', () => {
const wrapper = mount(Tag, {
props: {
show: false,
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('should not trigger click event when clicking the close icon', () => {
const onClick = jest.fn();
const wrapper = mount(Tag, {
props: {
onClick,
closeable: true,
},
});
wrapper.find('.van-tag__close').trigger('click');
expect(onClick).toHaveBeenCalledTimes(0);
wrapper.trigger('click');
expect(onClick).toHaveBeenCalledTimes(1);
});