mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-29 21:06:33 +08:00
test(Tag): update test cases
This commit is contained in:
parent
9bd38cf446
commit
3093ee1d84
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