test(Tag): update test cases
This commit is contained in:
@@ -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);
|
|
||||||
});
|
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user