test(Icon): update test cases

This commit is contained in:
chenjiahan 2020-11-14 06:53:25 +08:00
parent 2550ac9111
commit a13f4fd1e4
4 changed files with 111 additions and 103 deletions

View File

@ -1,38 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`dot prop 1`] = `
<i class="van-icon van-icon-undefined">
<div class="van-badge van-badge--dot"></div>
</i>
`;
exports[`render icon default slot 1`] = `
<i class="van-icon van-icon-success">Default slot
<!----></i>
`;
exports[`render icon with builtin icon name 1`] = `
<i class="van-icon van-icon-success">
<!----></i>
`;
exports[`render icon with local image 1`] = `
<i class="van-icon"><img src="/assets/icon.jpg" class="van-icon__image">
<!----></i>
`;
exports[`render icon with url name 1`] = `
<i class="van-icon"><img src="https://img.yzcdn.com/icon.jpg" class="van-icon__image">
<!----></i>
`;
exports[`size without unit 1`] = `
<i class="van-icon van-icon-undefined" style="font-size: 20px;">
<!----></i>
`;
exports[`tag prop 1`] = `
<div class="van-icon van-icon-undefined">
<!---->
</div>
`;

View File

@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`should render badge correctly 1`] = `<div class="van-badge van-badge--fixed">1</div>`;
exports[`should render default slot correctly 1`] = `
<i class="van-badge__wrapper van-icon van-icon-success">Default Slot
<!---->
<!----></i>
`;
exports[`should render dot correctly 1`] = `
<div class="van-badge van-badge--dot van-badge--fixed">
<!---->
</div>
`;
exports[`should render icon with builtin icon name correctly 1`] = `
<i class="van-badge__wrapper van-icon van-icon-success">
<!---->
<!---->
<!----></i>
`;
exports[`should render icon with local image correctly 1`] = `
<i class="van-badge__wrapper van-icon">
<!----><img class="van-icon__image" src="/assets/icon.jpg">
<!----></i>
`;
exports[`should render icon with url name correctly 1`] = `
<i class="van-badge__wrapper van-icon">
<!----><img class="van-icon__image" src="https://img.yzcdn.com/icon.jpg">
<!----></i>
`;

View File

@ -1,65 +0,0 @@
import Icon from '..';
import { mount } from '@vue/test-utils';
test('render icon with builtin icon name', () => {
const wrapper = mount(Icon, {
props: {
name: 'success',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('render icon with url name', () => {
const wrapper = mount(Icon, {
props: {
name: 'https://img.yzcdn.com/icon.jpg',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('render icon with local image', () => {
const wrapper = mount(Icon, {
props: {
name: '/assets/icon.jpg',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('render icon default slot', () => {
const wrapper = mount({
render(h) {
return h(Icon, { props: { name: 'success' } }, ['Default slot']);
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('tag prop', () => {
const wrapper = mount(Icon, {
props: {
tag: 'div',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('dot prop', () => {
const wrapper = mount(Icon, {
props: {
dot: true,
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('size without unit', () => {
const wrapper = mount(Icon, {
props: {
size: 20,
},
});
expect(wrapper.html()).toMatchSnapshot();
});

View File

@ -0,0 +1,77 @@
import Icon from '..';
import { mount } from '@vue/test-utils';
test('should render icon with builtin icon name correctly', () => {
const wrapper = mount(Icon, {
props: {
name: 'success',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('should render icon with url name correctly', () => {
const wrapper = mount(Icon, {
props: {
name: 'https://img.yzcdn.com/icon.jpg',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('should render icon with local image correctly', () => {
const wrapper = mount(Icon, {
props: {
name: '/assets/icon.jpg',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('should render default slot correctly', () => {
const wrapper = mount(Icon, {
props: {
name: 'success',
},
slots: {
default: () => 'Default Slot',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
test('should change root tag after using tag prop', () => {
const wrapper = mount(Icon, {
props: {
tag: 'div',
},
});
expect(wrapper.element.tagName).toEqual('DIV');
});
test('should render dot correctly', () => {
const wrapper = mount(Icon, {
props: {
dot: true,
},
});
expect(wrapper.find('.van-badge').html()).toMatchSnapshot();
});
test('should render badge correctly', () => {
const wrapper = mount(Icon, {
props: {
badge: '1',
},
});
expect(wrapper.find('.van-badge').html()).toMatchSnapshot();
});
test('should change icon size after using size prop', () => {
const wrapper = mount(Icon, {
props: {
size: 20,
},
});
expect(wrapper.element.style.fontSize).toEqual('20px');
});