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

@ -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);
});