diff --git a/src/contact-card/test/__snapshots__/index.legacy.js.snap b/src/contact-card/test/__snapshots__/index.legacy.js.snap deleted file mode 100644 index 8946ba610..000000000 --- a/src/contact-card/test/__snapshots__/index.legacy.js.snap +++ /dev/null @@ -1,19 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render ContactList correctly 1`] = ` -
-
-
- -
test,123123213
- -
-
-
-
-`; diff --git a/src/contact-list/index.js b/src/contact-list/index.js index 5fbbdf688..aef9e6bbc 100644 --- a/src/contact-list/index.js +++ b/src/contact-list/index.js @@ -33,7 +33,7 @@ export default createComponent({ ); - const renderLeftIcon = () => ( + const renderEditIcon = () => ( -
-
- -
test,123123213
- -
-
-
- -`; diff --git a/src/contact-list/test/__snapshots__/index.spec.js.snap b/src/contact-list/test/__snapshots__/index.spec.js.snap new file mode 100644 index 000000000..0d02c2c45 --- /dev/null +++ b/src/contact-list/test/__snapshots__/index.spec.js.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render ContactList correctly 1`] = ` +
+
+
+ + +
+ jack,12345678 +
+ +
+
+
+ +
+
+`; diff --git a/src/contact-list/test/index.legacy.js b/src/contact-list/test/index.legacy.js deleted file mode 100644 index 5c6e7681e..000000000 --- a/src/contact-list/test/index.legacy.js +++ /dev/null @@ -1,34 +0,0 @@ -import ContactList from '..'; -import { mount } from '@vue/test-utils'; - -const contactInfo = { - name: 'test', - tel: '123123213', -}; - -test('should render ContactList correctly', () => { - const wrapper = mount(ContactList, { - props: { - list: [contactInfo], - }, - }); - expect(wrapper).toMatchSnapshot(); -}); - -test('should emit select event after clicking the radio', () => { - const onSelect = jest.fn(); - const wrapper = mount(ContactList, { - props: { - list: [contactInfo], - }, - context: { - on: { - select: onSelect, - }, - }, - }); - - wrapper.find('.van-radio__icon').trigger('click'); - - expect(onSelect).toHaveBeenCalled(); -}); diff --git a/src/contact-list/test/index.spec.js b/src/contact-list/test/index.spec.js new file mode 100644 index 000000000..078e59cd4 --- /dev/null +++ b/src/contact-list/test/index.spec.js @@ -0,0 +1,48 @@ +import ContactList from '..'; +import { mount } from '@vue/test-utils'; + +const contactInfo = { + name: 'jack', + tel: '12345678', +}; + +test('should render ContactList correctly', () => { + const wrapper = mount(ContactList, { + props: { + list: [contactInfo], + }, + }); + expect(wrapper.html()).toMatchSnapshot(); +}); + +test('should emit add event when add button is clicked', () => { + const wrapper = mount(ContactList); + wrapper.find('.van-contact-list__add').trigger('click'); + expect(wrapper.emitted('add').length).toEqual(1); +}); + +test('should emit select event when radio is clicked', () => { + const wrapper = mount(ContactList, { + props: { + list: [contactInfo], + }, + }); + + wrapper.find('.van-radio__icon').trigger('click'); + + expect(wrapper.emitted('select').length).toEqual(1); + expect(wrapper.emitted('select')[0]).toEqual([contactInfo, 0]); +}); + +test('should emit edit event when edit icon is clicked', () => { + const wrapper = mount(ContactList, { + props: { + list: [contactInfo], + }, + }); + + wrapper.find('.van-contact-list__edit').trigger('click'); + + expect(wrapper.emitted('edit').length).toEqual(1); + expect(wrapper.emitted('edit')[0]).toEqual([contactInfo, 0]); +});