diff --git a/src/icon/test/__snapshots__/index.legacy.js.snap b/src/icon/test/__snapshots__/index.legacy.js.snap deleted file mode 100644 index c5fb94374..000000000 --- a/src/icon/test/__snapshots__/index.legacy.js.snap +++ /dev/null @@ -1,38 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`dot prop 1`] = ` - -
-
-`; - -exports[`render icon default slot 1`] = ` -Default slot - -`; - -exports[`render icon with builtin icon name 1`] = ` - - -`; - -exports[`render icon with local image 1`] = ` - - -`; - -exports[`render icon with url name 1`] = ` - - -`; - -exports[`size without unit 1`] = ` - - -`; - -exports[`tag prop 1`] = ` -
- -
-`; diff --git a/src/icon/test/__snapshots__/index.spec.js.snap b/src/icon/test/__snapshots__/index.spec.js.snap new file mode 100644 index 000000000..c0001cea4 --- /dev/null +++ b/src/icon/test/__snapshots__/index.spec.js.snap @@ -0,0 +1,34 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render badge correctly 1`] = `
1
`; + +exports[`should render default slot correctly 1`] = ` +Default Slot + + +`; + +exports[`should render dot correctly 1`] = ` +
+ +
+`; + +exports[`should render icon with builtin icon name correctly 1`] = ` + + + + +`; + +exports[`should render icon with local image correctly 1`] = ` + + + +`; + +exports[`should render icon with url name correctly 1`] = ` + + + +`; diff --git a/src/icon/test/index.legacy.js b/src/icon/test/index.legacy.js deleted file mode 100644 index bdffd2d0c..000000000 --- a/src/icon/test/index.legacy.js +++ /dev/null @@ -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(); -}); diff --git a/src/icon/test/index.spec.js b/src/icon/test/index.spec.js new file mode 100644 index 000000000..a609eac19 --- /dev/null +++ b/src/icon/test/index.spec.js @@ -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'); +});