From c6a8727d2b685df5ed3bc730d342c6356cdc6e08 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 30 May 2018 14:12:43 +0800 Subject: [PATCH] test: update snapshots & some test --- .../auto-complete/__tests__/index.test.js | 14 +- components/calendar/__tests__/index.test.js | 21 +- components/form/demo/advanced-search.vue | 1 - .../__snapshots__/index.test.js.snap | 236 +++++++++--------- .../locale-provider/__tests__/index.test.js | 6 +- .../table/__tests__/Table.filter.test.js | 24 +- .../table/__tests__/Table.pagination.test.js | 8 +- 7 files changed, 165 insertions(+), 145 deletions(-) diff --git a/components/auto-complete/__tests__/index.test.js b/components/auto-complete/__tests__/index.test.js index 8ebdc7d3b..97c211040 100644 --- a/components/auto-complete/__tests__/index.test.js +++ b/components/auto-complete/__tests__/index.test.js @@ -21,11 +21,15 @@ describe('AutoComplete with Custom Input Element Render', () => { input.element.value = '123' input.trigger('input') Vue.nextTick(() => { - const popupComponent = wrapper.find({ name: 'Trigger' }).vm._component - expect($$('.ant-select-dropdown-menu-item').length).toBe(3) - expect(popupComponent).not.toBe(null) - expect(popupComponent).not.toBe(undefined) - done() + mount({ + render () { + return wrapper.find({ name: 'Trigger' }).vm.getComponent() + }, + }, { sync: false }) + Vue.nextTick(() => { + expect($$('.ant-select-dropdown-menu-item').length).toBe(3) + done() + }) }) }) }) diff --git a/components/calendar/__tests__/index.test.js b/components/calendar/__tests__/index.test.js index a931b3522..6426b3016 100644 --- a/components/calendar/__tests__/index.test.js +++ b/components/calendar/__tests__/index.test.js @@ -47,7 +47,8 @@ describe('Calendar', () => { render () { return }, - } + }, + { sync: false } ) wrapper.findAll('[title="February 20, 2018"]').at(0).trigger('click') expect(wrapper.find('[title="February 20, 2018"]').classes()).toContain('ant-fullcalendar-disabled-cell') @@ -85,14 +86,14 @@ describe('Calendar', () => { { sync: false } ) wrapper.find('.ant-fullcalendar-year-select').trigger('click') - Vue.nextTick(() => { + setTimeout(() => { $$('.ant-select-dropdown-menu-item')[0].click() wrapper.find('.ant-fullcalendar-month-select').trigger('click') - Vue.nextTick(() => { + setTimeout(() => { expect($$('.ant-select-dropdown-menu-item').length).toBe(13) done() - }) - }) + }, 1000) + }, 1000) }) it('getDateRange should returns a disabledDate function', () => { @@ -103,6 +104,7 @@ describe('Calendar', () => { validRange, defaultValue: Moment('2018-02-02'), }, + sync: false, } ) const instance = wrapper.vm @@ -123,7 +125,7 @@ describe('Calendar', () => { }) }) - it('Calendar should switch mode', () => { + it('Calendar should switch mode', (done) => { const monthMode = 'month' const yearMode = 'year' const onPanelChangeStub = jest.fn() @@ -140,7 +142,10 @@ describe('Calendar', () => { ) expect(wrapper.vm.sMode).toEqual(yearMode) wrapper.vm.setType('date') - expect(wrapper.vm.sMode).toEqual(monthMode) - expect(onPanelChangeStub).toHaveBeenCalledTimes(1) + Vue.nextTick(() => { + expect(wrapper.vm.sMode).toEqual(monthMode) + expect(onPanelChangeStub).toHaveBeenCalledTimes(1) + done() + }) }) }) diff --git a/components/form/demo/advanced-search.vue b/components/form/demo/advanced-search.vue index 1a2be9e5c..832a7c917 100644 --- a/components/form/demo/advanced-search.vue +++ b/components/form/demo/advanced-search.vue @@ -91,7 +91,6 @@ export default { methods: { saveFormRef (inst) { this.formRef = inst - console.log('formRef', this.formRef) }, }, render () { diff --git a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap index 64cba9490..c99588a8d 100644 --- a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap +++ b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap @@ -1,6 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Locale Provider set moment locale when locale changes 1`] = ` +
+
+
@@ -182,15 +185,15 @@ exports[`Locale Provider set moment locale when locale changes 1`] = `
-
-
-
`; exports[`Locale Provider set moment locale when locale changes 2`] = ` +
+
+
-
+
@@ -370,12 +373,12 @@ exports[`Locale Provider set moment locale when locale changes 2`] = `
-
-
-
`; exports[`Locale Provider set moment locale when locale changes 3`] = ` +
+
+
@@ -558,9 +561,6 @@ exports[`Locale Provider set moment locale when locale changes 3`] = `
-
-
-
`; exports[`Locale Provider should display the text as ar 1`] = ` @@ -604,12 +604,12 @@ exports[`Locale Provider should display the text as ar 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -1008,12 +1008,12 @@ exports[`Locale Provider should display the text as bg 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -1412,12 +1412,12 @@ exports[`Locale Provider should display the text as ca 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -1816,12 +1816,12 @@ exports[`Locale Provider should display the text as cs 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -2220,12 +2220,12 @@ exports[`Locale Provider should display the text as de 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -2624,12 +2624,12 @@ exports[`Locale Provider should display the text as el 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -3028,12 +3028,12 @@ exports[`Locale Provider should display the text as en 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -3432,12 +3432,12 @@ exports[`Locale Provider should display the text as en-gb 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -3836,12 +3836,12 @@ exports[`Locale Provider should display the text as es 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -4240,12 +4240,12 @@ exports[`Locale Provider should display the text as et 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -4644,12 +4644,12 @@ exports[`Locale Provider should display the text as fa 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -5048,12 +5048,12 @@ exports[`Locale Provider should display the text as fi 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -5452,12 +5452,12 @@ exports[`Locale Provider should display the text as fr 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -5856,12 +5856,12 @@ exports[`Locale Provider should display the text as fr 2`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -6260,12 +6260,12 @@ exports[`Locale Provider should display the text as is 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -6664,12 +6664,12 @@ exports[`Locale Provider should display the text as it 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -7068,12 +7068,12 @@ exports[`Locale Provider should display the text as ja 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -7472,12 +7472,12 @@ exports[`Locale Provider should display the text as ko 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -7876,12 +7876,12 @@ exports[`Locale Provider should display the text as ku-iq 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -8280,12 +8280,12 @@ exports[`Locale Provider should display the text as nb 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -8684,12 +8684,12 @@ exports[`Locale Provider should display the text as nl 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -9088,12 +9088,12 @@ exports[`Locale Provider should display the text as nl-be 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -9492,12 +9492,12 @@ exports[`Locale Provider should display the text as pl 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -9896,12 +9896,12 @@ exports[`Locale Provider should display the text as pt 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -10300,12 +10300,12 @@ exports[`Locale Provider should display the text as pt-br 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -10704,12 +10704,12 @@ exports[`Locale Provider should display the text as ru 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -11108,12 +11108,12 @@ exports[`Locale Provider should display the text as sk 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -11512,12 +11512,12 @@ exports[`Locale Provider should display the text as sl 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -11916,12 +11916,12 @@ exports[`Locale Provider should display the text as sr 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -12320,12 +12320,12 @@ exports[`Locale Provider should display the text as sv 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -12724,12 +12724,12 @@ exports[`Locale Provider should display the text as th 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -13128,12 +13128,12 @@ exports[`Locale Provider should display the text as tr 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -13532,12 +13532,12 @@ exports[`Locale Provider should display the text as uk 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -13936,12 +13936,12 @@ exports[`Locale Provider should display the text as vi 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -14340,12 +14340,12 @@ exports[`Locale Provider should display the text as zh-cn 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
@@ -14744,12 +14744,12 @@ exports[`Locale Provider should display the text as zh-tw 1`] = `  
-
-
~ +
+
~ - Click to confirm + Click to confirm
diff --git a/components/locale-provider/__tests__/index.test.js b/components/locale-provider/__tests__/index.test.js index 366f0c26b..d94b91967 100644 --- a/components/locale-provider/__tests__/index.test.js +++ b/components/locale-provider/__tests__/index.test.js @@ -175,13 +175,13 @@ describe('Locale Provider', () => { }, } const wrapper = mount(Test, { sync: false, attachToDocument: true }) - Vue.nextTick(() => { + setTimeout(() => { expect(document.body.innerHTML).toMatchSnapshot() wrapper.setData({ locale: frFR }) - Vue.nextTick(() => { + setTimeout(() => { expect(document.body.innerHTML).toMatchSnapshot() wrapper.setData({ locale: null }) - Vue.nextTick(() => { + setTimeout(() => { expect(document.body.innerHTML).toMatchSnapshot() done() }) diff --git a/components/table/__tests__/Table.filter.test.js b/components/table/__tests__/Table.filter.test.js index 85623688a..68f729283 100644 --- a/components/table/__tests__/Table.filter.test.js +++ b/components/table/__tests__/Table.filter.test.js @@ -61,8 +61,12 @@ describe('Table.filter', () => { it('renders menu correctly', (done) => { const wrapper = mount(Table, getTableOptions()) Vue.nextTick(() => { - const dropdownWrapper = wrapper.find({ name: 'Trigger' }).vm.renderComponent() - expect(dropdownWrapper.$el.outerHTML).toMatchSnapshot() + const dropdownWrapper = mount({ + render () { + return wrapper.find({ name: 'Trigger' }).vm.getComponent() + }, + }) + expect(dropdownWrapper.html()).toMatchSnapshot() done() }) }) @@ -75,8 +79,12 @@ describe('Table.filter', () => { }], })) Vue.nextTick(() => { - const dropdownWrapper = wrapper.find({ name: 'Trigger' }).vm.renderComponent() - expect(dropdownWrapper.$el.outerHTML).toMatchSnapshot() + const dropdownWrapper = mount({ + render () { + return wrapper.find({ name: 'Trigger' }).vm.getComponent() + }, + }) + expect(dropdownWrapper.html()).toMatchSnapshot() done() }) }) @@ -97,8 +105,12 @@ describe('Table.filter', () => { }) Vue.nextTick(() => { - const dropdownWrapper = wrapper.find({ name: 'Trigger' }).vm.renderComponent() - expect(dropdownWrapper.$el.outerHTML).toMatchSnapshot() + const dropdownWrapper = mount({ + render () { + return wrapper.find({ name: 'Trigger' }).vm.getComponent() + }, + }) + expect(dropdownWrapper.html()).toMatchSnapshot() done() }) }) diff --git a/components/table/__tests__/Table.pagination.test.js b/components/table/__tests__/Table.pagination.test.js index 961e0d37d..f8a99f0f5 100644 --- a/components/table/__tests__/Table.pagination.test.js +++ b/components/table/__tests__/Table.pagination.test.js @@ -188,21 +188,21 @@ describe('Table.pagination', () => { it('specify the position of pagination', (done) => { const wrapper = mount(Table, getTableOptions({ pagination: { position: 'top' }})) - Vue.nextTick(() => { + setTimeout(() => { expect(wrapper.findAll('.ant-spin-container > *')).toHaveLength(2) expect(wrapper.findAll('.ant-spin-container > *').at(0).findAll('.ant-pagination')).toHaveLength(1) wrapper.setProps({ pagination: { position: 'bottom' }}) - Vue.nextTick(() => { + setTimeout(() => { expect(wrapper.findAll('.ant-spin-container > *')).toHaveLength(2) expect(wrapper.findAll('.ant-spin-container > *').at(1).findAll('.ant-pagination')).toHaveLength(1) wrapper.setProps({ pagination: { position: 'both' }}) - Vue.nextTick(() => { + setTimeout(() => { expect(wrapper.findAll('.ant-spin-container > *')).toHaveLength(3) expect(wrapper.findAll('.ant-spin-container > *').at(0).findAll('.ant-pagination')).toHaveLength(1) expect(wrapper.findAll('.ant-spin-container > *').at(2).findAll('.ant-pagination')).toHaveLength(1) done() }) }) - }) + }, 0) }) })