diff --git a/src/address-list/test/__snapshots__/index.legacy.js.snap b/src/address-list/test/__snapshots__/index.legacy.js.snap deleted file mode 100644 index 4b8ac0806..000000000 --- a/src/address-list/test/__snapshots__/index.legacy.js.snap +++ /dev/null @@ -1,29 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`unswitchable 1`] = ` -
-
-
-
-
-
张三 13000000000
-
浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室
-
- -
-
-
-
-
-
李四 1310000000
-
浙江省杭州市拱墅区莫干山路 50 号
-
- -
-
-
-
-
-`; diff --git a/src/address-list/test/index.legacy.js b/src/address-list/test/index.legacy.js deleted file mode 100644 index 613691a38..000000000 --- a/src/address-list/test/index.legacy.js +++ /dev/null @@ -1,64 +0,0 @@ -import { mount } from '@vue/test-utils'; -import AddressList from '..'; - -const list = [ - { - id: '1', - name: '张三', - tel: '13000000000', - address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室', - }, - { - id: '2', - name: '李四', - tel: '1310000000', - address: '浙江省杭州市拱墅区莫干山路 50 号', - }, -]; - -test('unswitchable', () => { - const wrapper = mount(AddressList, { - props: { - list, - switchable: false, - }, - }); - - expect(wrapper.html()).toMatchSnapshot(); -}); - -test('select event', () => { - const onSelect = jest.fn(); - const wrapper = mount(AddressList, { - props: { - list, - }, - context: { - on: { - select: onSelect, - }, - }, - }); - - wrapper.find('.van-radio__icon').trigger('click'); - - expect(onSelect).toHaveBeenCalledTimes(1); -}); - -test('click-item event', () => { - const onClickItem = jest.fn(); - const wrapper = mount(AddressList, { - props: { - list, - }, - context: { - on: { - 'click-item': onClickItem, - }, - }, - }); - - wrapper.find('.van-address-item').trigger('click'); - - expect(onClickItem).toHaveBeenCalledTimes(1); -}); diff --git a/src/address-list/test/index.spec.js b/src/address-list/test/index.spec.js new file mode 100644 index 000000000..ed297d8e5 --- /dev/null +++ b/src/address-list/test/index.spec.js @@ -0,0 +1,52 @@ +import { mount } from '@vue/test-utils'; +import AddressList from '..'; + +const list = [ + { + id: '1', + name: 'Name 1', + tel: '13000000000', + address: 'Address 1', + }, + { + id: '2', + name: 'Name 2', + tel: '1310000000', + address: 'Address 2', + }, +]; + +test('should not render Radio when switchable is false', async () => { + const wrapper = mount(AddressList, { + props: { + list, + switchable: false, + }, + }); + + expect(wrapper.find('.van-radio').exists()).toBeFalsy(); +}); + +test('should emit select event after clicking radio icon', () => { + const wrapper = mount(AddressList, { + props: { + list, + }, + }); + + wrapper.find('.van-radio__icon').trigger('click'); + + expect(wrapper.emitted('select')[0]).toEqual([list[0], 0]); +}); + +test('should emit click-item event when item is clicked', () => { + const wrapper = mount(AddressList, { + props: { + list, + }, + }); + + wrapper.find('.van-address-item').trigger('click'); + + expect(wrapper.emitted('click-item')[0]).toEqual([list[0], 0]); +});