mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
test(Tag): update test cases
This commit is contained in:
parent
9bd38cf446
commit
3093ee1d84
@ -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
|
||||
|
7
src/tag/test/__snapshots__/index.spec.js.snap
Normal file
7
src/tag/test/__snapshots__/index.spec.js.snap
Normal 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>
|
||||
`;
|
@ -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);
|
||||
});
|
38
src/tag/test/index.spec.js
Normal file
38
src/tag/test/index.spec.js
Normal 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);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user