From 5026ae5fc5a5be16bfe72c8db165297622321e82 Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 29 Aug 2020 00:32:52 -0400 Subject: [PATCH 1/3] docs(createwrapper): remove sync mode from RU docs --- docs/ru/api/createWrapper.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/ru/api/createWrapper.md b/docs/ru/api/createWrapper.md index 1d791d306..fd852a7fc 100644 --- a/docs/ru/api/createWrapper.md +++ b/docs/ru/api/createWrapper.md @@ -4,7 +4,6 @@ - `{vm|HTMLElement} node` - `{Object} options` - - `{Boolean} sync` - `{Boolean} attachedToDocument` - **Возвращает:** From 756e6e85b14916f15363ffa0971260844274eb9a Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 29 Aug 2020 00:34:40 -0400 Subject: [PATCH 2/3] chore(flow): remove sync option from config options --- flow/options.flow.js | 1 - 1 file changed, 1 deletion(-) diff --git a/flow/options.flow.js b/flow/options.flow.js index 992cf3d8b..4a744edb5 100644 --- a/flow/options.flow.js +++ b/flow/options.flow.js @@ -32,7 +32,6 @@ declare type NormalizedOptions = { attrs?: { [key: string]: string }, listeners?: { [key: string]: Function | Array }, parentComponent?: Object, - sync: boolean, shouldProxy?: boolean } From 64f7ab67ae3941b31afbaf0274ff6cef9cd8306c Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 29 Aug 2020 00:36:40 -0400 Subject: [PATCH 3/3] improvement(tests): write Tests to fit async API signature Update tests, where applicable, to be awaited. This includes trigger, setValue, setSelected, setProps, setData, setChecked --- test/specs/create-local-vue.spec.js | 7 +-- test/specs/mounting-options/propsData.spec.js | 4 +- .../mounting-options/scopedSlots.spec.js | 46 +++++++-------- test/specs/wrapper-array/setChecked.spec.js | 4 +- test/specs/wrapper-array/setData.spec.js | 5 +- test/specs/wrapper-array/setProps.spec.js | 9 ++- test/specs/wrapper-array/setValue.spec.js | 4 +- test/specs/wrapper-array/trigger.spec.js | 12 ++-- test/specs/wrapper/setChecked.spec.js | 26 ++++---- test/specs/wrapper/setData.spec.js | 16 ++--- test/specs/wrapper/setProps.spec.js | 14 ++--- test/specs/wrapper/setSelected.spec.js | 8 +-- test/specs/wrapper/setValue.spec.js | 18 +++--- test/specs/wrapper/trigger.spec.js | 59 +++++++++---------- 14 files changed, 111 insertions(+), 121 deletions(-) diff --git a/test/specs/create-local-vue.spec.js b/test/specs/create-local-vue.spec.js index 09a928a01..822231d1f 100644 --- a/test/specs/create-local-vue.spec.js +++ b/test/specs/create-local-vue.spec.js @@ -47,8 +47,7 @@ describeWithShallowAndMount('createLocalVue', mountingMethod => { const wrapper = mountingMethod(ComponentWithVuex, { localVue, store }) expect(wrapper.vm.$store).toBeTruthy() expect(wrapper.text()).toEqual('0 1') - wrapper.trigger('click') - await Vue.nextTick() + await wrapper.trigger('click') expect(wrapper.text()).toEqual('1 1') }) @@ -68,7 +67,7 @@ describeWithShallowAndMount('createLocalVue', mountingMethod => { itDoNotRunIf( mountingMethod.name === 'shallowMount', 'Router should work properly with local Vue', - () => { + async () => { const localVue = createLocalVue() localVue.use(VueRouter) const routes = [ @@ -93,7 +92,7 @@ describeWithShallowAndMount('createLocalVue', mountingMethod => { expect(wrapper.text()).toContain('home') - wrapper.find('a').trigger('click') + await wrapper.find('a').trigger('click') expect(wrapper.text()).toContain('foo') const freshWrapper = mountingMethod(Component) diff --git a/test/specs/mounting-options/propsData.spec.js b/test/specs/mounting-options/propsData.spec.js index 120e403ca..cc25c5938 100644 --- a/test/specs/mounting-options/propsData.spec.js +++ b/test/specs/mounting-options/propsData.spec.js @@ -20,9 +20,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'propsData', () => { }) describe('should not modify propsData between tests', () => { - it('should have the correct props after modifying', () => { + it('should have the correct props after modifying', async () => { expect(wrapper.vm.prop1).toHaveLength(2) - wrapper.setProps({ prop1: [] }) + await wrapper.setProps({ prop1: [] }) expect(wrapper.vm.prop1).toHaveLength(0) }) diff --git a/test/specs/mounting-options/scopedSlots.spec.js b/test/specs/mounting-options/scopedSlots.spec.js index 7db63c449..e50b9c78e 100644 --- a/test/specs/mounting-options/scopedSlots.spec.js +++ b/test/specs/mounting-options/scopedSlots.spec.js @@ -241,34 +241,30 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } ) - itDoNotRunIf( - vueVersion < 2.5, - 'renders scoped slots in sync mode by default', - async () => { - const TestComponent = { - template: '
', - data() { - return { - val: null - } - }, - mounted() { - this.val = 123 - }, - render() { - return this.$scopedSlots.default(this.val) + itDoNotRunIf(vueVersion < 2.5, 'renders scoped slots', async () => { + const TestComponent = { + template: '
', + data() { + return { + val: null } + }, + mounted() { + this.val = 123 + }, + render() { + return this.$scopedSlots.default(this.val) } - const stub = jest.fn() - mountingMethod(TestComponent, { - scopedSlots: { - default: stub - } - }) - await Vue.nextTick() - expect(stub).toHaveBeenCalledWith(123) } - ) + const stub = jest.fn() + mountingMethod(TestComponent, { + scopedSlots: { + default: stub + } + }) + await Vue.nextTick() + expect(stub).toHaveBeenCalledWith(123) + }) itDoNotRunIf( vueVersion < 2.6, diff --git a/test/specs/wrapper-array/setChecked.spec.js b/test/specs/wrapper-array/setChecked.spec.js index b4358e361..201ca2e27 100644 --- a/test/specs/wrapper-array/setChecked.spec.js +++ b/test/specs/wrapper-array/setChecked.spec.js @@ -1,5 +1,4 @@ import { describeWithShallowAndMount } from '~resources/utils' -import Vue from 'vue' describeWithShallowAndMount('setChecked', mountingMethod => { it('sets value to the input elements of type checkbox or radio', async () => { @@ -20,8 +19,7 @@ describeWithShallowAndMount('setChecked', mountingMethod => { const wrapperArray = wrapper.findAll('.foo') expect(wrapper.vm.t1).toEqual(false) expect(wrapper.vm.t2).toEqual('') - wrapperArray.setChecked() - await Vue.nextTick() + await wrapperArray.setChecked() expect(wrapper.vm.t1).toEqual(true) expect(wrapper.vm.t2).toEqual('foo') expect(wrapperArray.at(0).element.checked).toEqual(true) diff --git a/test/specs/wrapper-array/setData.spec.js b/test/specs/wrapper-array/setData.spec.js index 469aa06cf..f7833f607 100644 --- a/test/specs/wrapper-array/setData.spec.js +++ b/test/specs/wrapper-array/setData.spec.js @@ -1,15 +1,14 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithVIf from '~resources/components/component-with-v-if.vue' import { describeWithShallowAndMount } from '~resources/utils' -import Vue from 'vue' describeWithShallowAndMount('setData', mountingMethod => { it('sets component data and updates nested vm nodes', async () => { const wrapper = mountingMethod(ComponentWithVIf) const componentArr = wrapper.findAll(ComponentWithVIf) expect(componentArr.at(0).findAll('.child.ready').length).toEqual(0) - componentArr.setData({ ready: true }) - await Vue.nextTick() + await componentArr.setData({ ready: true }) + expect(componentArr.at(0).findAll('.child.ready').length).toEqual(1) }) diff --git a/test/specs/wrapper-array/setProps.spec.js b/test/specs/wrapper-array/setProps.spec.js index c7795f622..20556f041 100644 --- a/test/specs/wrapper-array/setProps.spec.js +++ b/test/specs/wrapper-array/setProps.spec.js @@ -1,7 +1,6 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithProps from '~resources/components/component-with-props.vue' import { describeWithShallowAndMount } from '~resources/utils' -import Vue from 'vue' describeWithShallowAndMount('setProps', mountingMethod => { it('sets component props and updates DOM when called on Vue instance', async () => { @@ -9,8 +8,8 @@ describeWithShallowAndMount('setProps', mountingMethod => { const prop2 = 'prop 2' const propsData = { prop1: 'a prop', prop2 } const wrapper = mountingMethod(ComponentWithProps, { propsData }) - wrapper.findAll(ComponentWithProps).setProps({ prop1 }) - await Vue.nextTick() + await wrapper.findAll(ComponentWithProps).setProps({ prop1 }) + expect(wrapper.find('.prop-1').element.textContent).toEqual(prop1) expect(wrapper.find('.prop-2').element.textContent).toEqual(prop2) }) @@ -19,8 +18,8 @@ describeWithShallowAndMount('setProps', mountingMethod => { const prop1 = 'prop 1' const prop2 = 'prop s' const wrapper = mountingMethod(ComponentWithProps) - wrapper.findAll(ComponentWithProps).setProps({ prop1, prop2 }) - await Vue.nextTick() + await wrapper.findAll(ComponentWithProps).setProps({ prop1, prop2 }) + expect(wrapper.find('.prop-1').element.textContent).toEqual(prop1) expect(wrapper.find('.prop-2').element.textContent).toEqual(prop2) }) diff --git a/test/specs/wrapper-array/setValue.spec.js b/test/specs/wrapper-array/setValue.spec.js index cc164a851..8f358afdb 100644 --- a/test/specs/wrapper-array/setValue.spec.js +++ b/test/specs/wrapper-array/setValue.spec.js @@ -1,7 +1,7 @@ import { describeWithShallowAndMount } from '~resources/utils' describeWithShallowAndMount('setValue', mountingMethod => { - it('sets value to the text-control input elements', () => { + it('sets value to the text-control input elements', async () => { const wrapper = mountingMethod({ data() { return { @@ -18,7 +18,7 @@ describeWithShallowAndMount('setValue', mountingMethod => { const wrapperArray = wrapper.findAll('.foo') expect(wrapper.vm.t1).toEqual('') expect(wrapper.vm.t2).toEqual('') - wrapperArray.setValue('foo') + await wrapperArray.setValue('foo') expect(wrapper.vm.t1).toEqual('foo') expect(wrapper.vm.t2).toEqual('foo') expect(wrapperArray.at(0).element.value).toEqual('foo') diff --git a/test/specs/wrapper-array/trigger.spec.js b/test/specs/wrapper-array/trigger.spec.js index 2592c6d2d..9ef116678 100644 --- a/test/specs/wrapper-array/trigger.spec.js +++ b/test/specs/wrapper-array/trigger.spec.js @@ -3,33 +3,33 @@ import ComponentWithEvents from '~resources/components/component-with-events.vue import { describeWithShallowAndMount } from '~resources/utils' describeWithShallowAndMount('trigger', mountingMethod => { - it('causes click handler to fire when wrapper.trigger("click") is called on a Component', () => { + it('causes click handler to fire when wrapper.trigger("click") is called on a Component', async () => { const clickHandler = jest.fn() const wrapper = mountingMethod(ComponentWithEvents, { propsData: { clickHandler } }) const buttonArr = wrapper.findAll('.click') - buttonArr.trigger('click') + await buttonArr.trigger('click') expect(clickHandler).toHaveBeenCalled() }) - it('causes keydown handler to fire when wrapper.trigger("keydown") is fired on a Component', () => { + it('causes keydown handler to fire when wrapper.trigger("keydown") is fired on a Component', async () => { const keydownHandler = jest.fn() const wrapper = mountingMethod(ComponentWithEvents, { propsData: { keydownHandler } }) - wrapper.findAll('.keydown').trigger('keydown') + await wrapper.findAll('.keydown').trigger('keydown') expect(keydownHandler).toHaveBeenCalled() }) - it('causes keydown handler to fire when wrapper.trigger("keydown.enter") is fired on a Component', () => { + it('causes keydown handler to fire when wrapper.trigger("keydown.enter") is fired on a Component', async () => { const keydownHandler = jest.fn() const wrapper = mountingMethod(ComponentWithEvents, { propsData: { keydownHandler } }) - wrapper.findAll('.keydown-enter').trigger('keydown.enter') + await wrapper.findAll('.keydown-enter').trigger('keydown.enter') expect(keydownHandler).toHaveBeenCalled() }) diff --git a/test/specs/wrapper/setChecked.spec.js b/test/specs/wrapper/setChecked.spec.js index 707d77570..00f970f6b 100644 --- a/test/specs/wrapper/setChecked.spec.js +++ b/test/specs/wrapper/setChecked.spec.js @@ -12,22 +12,22 @@ describeWithShallowAndMount('setChecked', mountingMethod => { await response expect(wrapper.text()).toContain('checkbox checked') }) - it('sets element checked true with no option passed', () => { + it('sets element checked true with no option passed', async () => { const wrapper = mountingMethod(ComponentWithInput) const input = wrapper.find('input[type="checkbox"]') - input.setChecked() + await input.setChecked() expect(input.element.checked).toEqual(true) }) - it('sets element checked equal to param passed', () => { + it('sets element checked equal to param passed', async () => { const wrapper = mountingMethod(ComponentWithInput) const input = wrapper.find('input[type="checkbox"]') - input.setChecked(true) + await input.setChecked(true) expect(input.element.checked).toEqual(true) - input.setChecked(false) + await input.setChecked(false) expect(input.element.checked).toEqual(false) }) @@ -56,10 +56,10 @@ describeWithShallowAndMount('setChecked', mountingMethod => { expect(wrapper.find('.counter').text()).toEqual('4') }) - it('triggers a change event when called on a checkbox', () => { + it('triggers a change event when called on a checkbox', async () => { const listener = jest.fn() - mountingMethod({ + await mountingMethod({ // For compatibility with earlier versions of Vue that use the `click` // event for updating `v-model`. template: ` @@ -75,10 +75,10 @@ describeWithShallowAndMount('setChecked', mountingMethod => { expect(listener).toHaveBeenCalled() }) - it('does not trigger a change event if the checkbox is already checked', () => { + it('does not trigger a change event if the checkbox is already checked', async () => { const listener = jest.fn() - mountingMethod({ + await mountingMethod({ template: ` { expect(wrapper.find('.counter').text()).toEqual('4') }) - it('triggers a change event when called on a radio button', () => { + it('triggers a change event when called on a radio button', async () => { const listener = jest.fn() - mountingMethod({ + await mountingMethod({ template: ` { expect(listener).toHaveBeenCalled() }) - it('does not trigger a change event if the radio button is already checked', () => { + it('does not trigger a change event if the radio button is already checked', async () => { const listener = jest.fn() - mountingMethod({ + await mountingMethod({ template: ` { expect(wrapper.text()).toEqual('There is no message yet') }) - it('updates an existing property in a data object', () => { + it('updates an existing property in a data object', async () => { const TestComponent = { data: () => ({ anObject: { @@ -166,7 +166,7 @@ describeWithShallowAndMount('setData', mountingMethod => { render: () => {} } const wrapper = mountingMethod(TestComponent) - wrapper.setData({ + await wrapper.setData({ anObject: { propA: { prop1: 'c' @@ -177,7 +177,7 @@ describeWithShallowAndMount('setData', mountingMethod => { expect(wrapper.vm.anObject.propA.prop1).toEqual('c') }) - it('should append a new property to an object without removing existing properties', () => { + it('should append a new property to an object without removing existing properties', async () => { const TestComponent = { data: () => ({ anObject: { @@ -190,7 +190,7 @@ describeWithShallowAndMount('setData', mountingMethod => { render: () => {} } const wrapper = mountingMethod(TestComponent) - wrapper.setData({ + await wrapper.setData({ anObject: { propA: { prop2: 'b' @@ -238,7 +238,7 @@ describeWithShallowAndMount('setData', mountingMethod => { } }) expect(wrapper.text()).toContain('bar') - wrapper.setData({ + await wrapper.setData({ nullProperty: { another: { obj: true @@ -261,7 +261,7 @@ describeWithShallowAndMount('setData', mountingMethod => { }) } const wrapper = mountingMethod(TestComponent) - wrapper.setData({ + await wrapper.setData({ items: [3] }) expect(wrapper.vm.items).toEqual([3]) @@ -304,7 +304,7 @@ describeWithShallowAndMount('setData', mountingMethod => { expect(wrapper.html()).toEqual('
propA,propB,propC
') }) - it('allows setting data of type Date synchronously', () => { + it('allows setting data of type Date synchronously', async () => { const TestComponent = { template: `
@@ -317,7 +317,7 @@ describeWithShallowAndMount('setData', mountingMethod => { } const testDate = new Date() const wrapper = mountingMethod(TestComponent) - wrapper.setData({ selectedDate: testDate }) + await wrapper.setData({ selectedDate: testDate }) expect(wrapper.vm.selectedDate).toEqual(testDate) }) }) diff --git a/test/specs/wrapper/setProps.spec.js b/test/specs/wrapper/setProps.spec.js index 604b17c9d..039be14a8 100644 --- a/test/specs/wrapper/setProps.spec.js +++ b/test/specs/wrapper/setProps.spec.js @@ -43,14 +43,14 @@ describeWithShallowAndMount('setProps', mountingMethod => { expect(wrapper.is('div')).toEqual(true) }) - it('setProps and props getter are in sync', () => { + it('setProps and props getter are in sync', async () => { const TestComponent = { template: `
`, props: { prop1: { default: 'initial value' } } } const wrapper = mountingMethod(TestComponent) const updatedValue = 'updated value' - wrapper.setProps({ prop1: updatedValue }) + await wrapper.setProps({ prop1: updatedValue }) expect(wrapper.props().prop1).toEqual(updatedValue) }) @@ -67,13 +67,13 @@ describeWithShallowAndMount('setProps', mountingMethod => { itDoNotRunIf( vueVersion < 2.4, 'attributes not recognized as props are available via the $attrs instance property', - () => { + async () => { const TestComponent = { template: '
' } const prop1 = 'prop1' const wrapper = mountingMethod(TestComponent) - wrapper.setProps({ prop1 }) + await wrapper.setProps({ prop1 }) expect(wrapper.vm.$attrs.prop1).toEqual(prop1) } ) @@ -262,14 +262,14 @@ describeWithShallowAndMount('setProps', mountingMethod => { ) }) - it('props and setProps should return the same reference when called with same object', () => { + it('props and setProps should return the same reference when called with same object', async () => { const TestComponent = { template: `
`, props: ['obj'] } const wrapper = mountingMethod(TestComponent) const obj = {} - wrapper.setProps({ obj }) + await wrapper.setProps({ obj }) expect(wrapper.props().obj).toEqual(obj) }) @@ -324,7 +324,7 @@ describeWithShallowAndMount('setProps', mountingMethod => { ) }) - it('throws an error if property is same reference', () => { + it('throws an error if property is same reference', async () => { const obj = {} const wrapper = mountingMethod( { diff --git a/test/specs/wrapper/setSelected.spec.js b/test/specs/wrapper/setSelected.spec.js index 8a58cc8c2..7119c84af 100644 --- a/test/specs/wrapper/setSelected.spec.js +++ b/test/specs/wrapper/setSelected.spec.js @@ -33,10 +33,10 @@ describeWithShallowAndMount('setSelected', mountingMethod => { expect(wrapper.text()).toContain('selectA') }) - it('triggers a change event on the parent select', () => { + it('triggers a change event on the parent select', async () => { const change = jest.fn() - mountingMethod({ + await mountingMethod({ template: `