Skip to content

Commit bd91c9f

Browse files
authored
Sync mode cleanup (#1671)
* docs(createwrapper): remove sync mode from RU docs * chore(flow): remove sync option from config options * improvement(tests): write Tests to fit async API signature Update tests, where applicable, to be awaited. This includes trigger, setValue, setSelected, setProps, setData, setChecked
1 parent e91effe commit bd91c9f

16 files changed

+111
-123
lines changed

docs/ru/api/createWrapper.md

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
- `{vm|HTMLElement} node`
66
- `{Object} options`
7-
- `{Boolean} sync`
87
- `{Boolean} attachedToDocument`
98

109
- **Возвращает:**

flow/options.flow.js

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ declare type NormalizedOptions = {
3232
attrs?: { [key: string]: string },
3333
listeners?: { [key: string]: Function | Array<Function> },
3434
parentComponent?: Object,
35-
sync: boolean,
3635
shouldProxy?: boolean
3736
}
3837

test/specs/create-local-vue.spec.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ describeWithShallowAndMount('createLocalVue', mountingMethod => {
4949
const wrapper = mountingMethod(ComponentWithVuex, { localVue, store })
5050
expect(wrapper.vm.$store).toBeTruthy()
5151
expect(wrapper.text()).toEqual('0 1')
52-
wrapper.trigger('click')
53-
await Vue.nextTick()
52+
await wrapper.trigger('click')
5453
expect(wrapper.text()).toEqual('1 1')
5554
})
5655

@@ -70,7 +69,7 @@ describeWithShallowAndMount('createLocalVue', mountingMethod => {
7069
itDoNotRunIf(
7170
mountingMethod.name === 'shallowMount',
7271
'Router should work properly with local Vue',
73-
() => {
72+
async () => {
7473
const localVue = createLocalVue()
7574
localVue.use(VueRouter)
7675
const routes = [
@@ -95,7 +94,7 @@ describeWithShallowAndMount('createLocalVue', mountingMethod => {
9594

9695
expect(wrapper.text()).toContain('home')
9796

98-
wrapper.find('a').trigger('click')
97+
await wrapper.find('a').trigger('click')
9998
expect(wrapper.text()).toContain('foo')
10099

101100
const freshWrapper = mountingMethod(Component)

test/specs/mounting-options/propsData.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'propsData', () => {
2020
})
2121

2222
describe('should not modify propsData between tests', () => {
23-
it('should have the correct props after modifying', () => {
23+
it('should have the correct props after modifying', async () => {
2424
expect(wrapper.vm.prop1).toHaveLength(2)
25-
wrapper.setProps({ prop1: [] })
25+
await wrapper.setProps({ prop1: [] })
2626
expect(wrapper.vm.prop1).toHaveLength(0)
2727
})
2828

test/specs/mounting-options/scopedSlots.spec.js

+21-25
Original file line numberDiff line numberDiff line change
@@ -241,34 +241,30 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
241241
}
242242
)
243243

244-
itDoNotRunIf(
245-
vueVersion < 2.5,
246-
'renders scoped slots in sync mode by default',
247-
async () => {
248-
const TestComponent = {
249-
template: '<div />',
250-
data() {
251-
return {
252-
val: null
253-
}
254-
},
255-
mounted() {
256-
this.val = 123
257-
},
258-
render() {
259-
return this.$scopedSlots.default(this.val)
244+
itDoNotRunIf(vueVersion < 2.5, 'renders scoped slots', async () => {
245+
const TestComponent = {
246+
template: '<div />',
247+
data() {
248+
return {
249+
val: null
260250
}
251+
},
252+
mounted() {
253+
this.val = 123
254+
},
255+
render() {
256+
return this.$scopedSlots.default(this.val)
261257
}
262-
const stub = jest.fn()
263-
mountingMethod(TestComponent, {
264-
scopedSlots: {
265-
default: stub
266-
}
267-
})
268-
await Vue.nextTick()
269-
expect(stub).toHaveBeenCalledWith(123)
270258
}
271-
)
259+
const stub = jest.fn()
260+
mountingMethod(TestComponent, {
261+
scopedSlots: {
262+
default: stub
263+
}
264+
})
265+
await Vue.nextTick()
266+
expect(stub).toHaveBeenCalledWith(123)
267+
})
272268

273269
itDoNotRunIf(
274270
vueVersion < 2.6,

test/specs/wrapper-array/setChecked.spec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
2-
import Vue from 'vue'
32

43
describeWithShallowAndMount('setChecked', mountingMethod => {
54
it('sets value to the input elements of type checkbox or radio', async () => {
@@ -20,8 +19,7 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
2019
const wrapperArray = wrapper.findAll('.foo')
2120
expect(wrapper.vm.t1).toEqual(false)
2221
expect(wrapper.vm.t2).toEqual('')
23-
wrapperArray.setChecked()
24-
await Vue.nextTick()
22+
await wrapperArray.setChecked()
2523
expect(wrapper.vm.t1).toEqual(true)
2624
expect(wrapper.vm.t2).toEqual('foo')
2725
expect(wrapperArray.at(0).element.checked).toEqual(true)

test/specs/wrapper-array/setData.spec.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { compileToFunctions } from 'vue-template-compiler'
22
import ComponentWithVIf from '~resources/components/component-with-v-if.vue'
33
import { describeWithShallowAndMount } from '~resources/utils'
4-
import Vue from 'vue'
54

65
describeWithShallowAndMount('setData', mountingMethod => {
76
it('sets component data and updates nested vm nodes', async () => {
87
const wrapper = mountingMethod(ComponentWithVIf)
98
const componentArr = wrapper.findAll(ComponentWithVIf)
109
expect(componentArr.at(0).findAll('.child.ready').length).toEqual(0)
11-
componentArr.setData({ ready: true })
12-
await Vue.nextTick()
10+
await componentArr.setData({ ready: true })
11+
1312
expect(componentArr.at(0).findAll('.child.ready').length).toEqual(1)
1413
})
1514

test/specs/wrapper-array/setProps.spec.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { compileToFunctions } from 'vue-template-compiler'
22
import ComponentWithProps from '~resources/components/component-with-props.vue'
33
import { describeWithShallowAndMount } from '~resources/utils'
4-
import Vue from 'vue'
54

65
describeWithShallowAndMount('setProps', mountingMethod => {
76
it('sets component props and updates DOM when called on Vue instance', async () => {
87
const prop1 = 'prop 1'
98
const prop2 = 'prop 2'
109
const propsData = { prop1: 'a prop', prop2 }
1110
const wrapper = mountingMethod(ComponentWithProps, { propsData })
12-
wrapper.findAll(ComponentWithProps).setProps({ prop1 })
13-
await Vue.nextTick()
11+
await wrapper.findAll(ComponentWithProps).setProps({ prop1 })
12+
1413
expect(wrapper.find('.prop-1').element.textContent).toEqual(prop1)
1514
expect(wrapper.find('.prop-2').element.textContent).toEqual(prop2)
1615
})
@@ -19,8 +18,8 @@ describeWithShallowAndMount('setProps', mountingMethod => {
1918
const prop1 = 'prop 1'
2019
const prop2 = 'prop s'
2120
const wrapper = mountingMethod(ComponentWithProps)
22-
wrapper.findAll(ComponentWithProps).setProps({ prop1, prop2 })
23-
await Vue.nextTick()
21+
await wrapper.findAll(ComponentWithProps).setProps({ prop1, prop2 })
22+
2423
expect(wrapper.find('.prop-1').element.textContent).toEqual(prop1)
2524
expect(wrapper.find('.prop-2').element.textContent).toEqual(prop2)
2625
})

test/specs/wrapper-array/setValue.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22

33
describeWithShallowAndMount('setValue', mountingMethod => {
4-
it('sets value to the text-control input elements', () => {
4+
it('sets value to the text-control input elements', async () => {
55
const wrapper = mountingMethod({
66
data() {
77
return {
@@ -18,7 +18,7 @@ describeWithShallowAndMount('setValue', mountingMethod => {
1818
const wrapperArray = wrapper.findAll('.foo')
1919
expect(wrapper.vm.t1).toEqual('')
2020
expect(wrapper.vm.t2).toEqual('')
21-
wrapperArray.setValue('foo')
21+
await wrapperArray.setValue('foo')
2222
expect(wrapper.vm.t1).toEqual('foo')
2323
expect(wrapper.vm.t2).toEqual('foo')
2424
expect(wrapperArray.at(0).element.value).toEqual('foo')

test/specs/wrapper-array/trigger.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ import ComponentWithEvents from '~resources/components/component-with-events.vue
33
import { describeWithShallowAndMount } from '~resources/utils'
44

55
describeWithShallowAndMount('trigger', mountingMethod => {
6-
it('causes click handler to fire when wrapper.trigger("click") is called on a Component', () => {
6+
it('causes click handler to fire when wrapper.trigger("click") is called on a Component', async () => {
77
const clickHandler = jest.fn()
88
const wrapper = mountingMethod(ComponentWithEvents, {
99
propsData: { clickHandler }
1010
})
1111
const buttonArr = wrapper.findAll('.click')
12-
buttonArr.trigger('click')
12+
await buttonArr.trigger('click')
1313

1414
expect(clickHandler).toHaveBeenCalled()
1515
})
1616

17-
it('causes keydown handler to fire when wrapper.trigger("keydown") is fired on a Component', () => {
17+
it('causes keydown handler to fire when wrapper.trigger("keydown") is fired on a Component', async () => {
1818
const keydownHandler = jest.fn()
1919
const wrapper = mountingMethod(ComponentWithEvents, {
2020
propsData: { keydownHandler }
2121
})
22-
wrapper.findAll('.keydown').trigger('keydown')
22+
await wrapper.findAll('.keydown').trigger('keydown')
2323

2424
expect(keydownHandler).toHaveBeenCalled()
2525
})
2626

27-
it('causes keydown handler to fire when wrapper.trigger("keydown.enter") is fired on a Component', () => {
27+
it('causes keydown handler to fire when wrapper.trigger("keydown.enter") is fired on a Component', async () => {
2828
const keydownHandler = jest.fn()
2929
const wrapper = mountingMethod(ComponentWithEvents, {
3030
propsData: { keydownHandler }
3131
})
32-
wrapper.findAll('.keydown-enter').trigger('keydown.enter')
32+
await wrapper.findAll('.keydown-enter').trigger('keydown.enter')
3333

3434
expect(keydownHandler).toHaveBeenCalled()
3535
})

test/specs/wrapper/setChecked.spec.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
1212
await response
1313
expect(wrapper.text()).toContain('checkbox checked')
1414
})
15-
it('sets element checked true with no option passed', () => {
15+
it('sets element checked true with no option passed', async () => {
1616
const wrapper = mountingMethod(ComponentWithInput)
1717
const input = wrapper.find('input[type="checkbox"]')
18-
input.setChecked()
18+
await input.setChecked()
1919

2020
expect(input.element.checked).toEqual(true)
2121
})
2222

23-
it('sets element checked equal to param passed', () => {
23+
it('sets element checked equal to param passed', async () => {
2424
const wrapper = mountingMethod(ComponentWithInput)
2525
const input = wrapper.find('input[type="checkbox"]')
2626

27-
input.setChecked(true)
27+
await input.setChecked(true)
2828
expect(input.element.checked).toEqual(true)
2929

30-
input.setChecked(false)
30+
await input.setChecked(false)
3131
expect(input.element.checked).toEqual(false)
3232
})
3333

@@ -56,10 +56,10 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
5656
expect(wrapper.find('.counter').text()).toEqual('4')
5757
})
5858

59-
it('triggers a change event when called on a checkbox', () => {
59+
it('triggers a change event when called on a checkbox', async () => {
6060
const listener = jest.fn()
6161

62-
mountingMethod({
62+
await mountingMethod({
6363
// For compatibility with earlier versions of Vue that use the `click`
6464
// event for updating `v-model`.
6565
template: `
@@ -75,10 +75,10 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
7575
expect(listener).toHaveBeenCalled()
7676
})
7777

78-
it('does not trigger a change event if the checkbox is already checked', () => {
78+
it('does not trigger a change event if the checkbox is already checked', async () => {
7979
const listener = jest.fn()
8080

81-
mountingMethod({
81+
await mountingMethod({
8282
template: `
8383
<input
8484
type="checkbox"
@@ -118,10 +118,10 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
118118
expect(wrapper.find('.counter').text()).toEqual('4')
119119
})
120120

121-
it('triggers a change event when called on a radio button', () => {
121+
it('triggers a change event when called on a radio button', async () => {
122122
const listener = jest.fn()
123123

124-
mountingMethod({
124+
await mountingMethod({
125125
template: `
126126
<input
127127
type="radio"
@@ -135,10 +135,10 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
135135
expect(listener).toHaveBeenCalled()
136136
})
137137

138-
it('does not trigger a change event if the radio button is already checked', () => {
138+
it('does not trigger a change event if the radio button is already checked', async () => {
139139
const listener = jest.fn()
140140

141-
mountingMethod({
141+
await mountingMethod({
142142
template: `
143143
<input
144144
type="radio"

test/specs/wrapper/setData.spec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describeWithShallowAndMount('setData', mountingMethod => {
153153
expect(wrapper.text()).toEqual('There is no message yet')
154154
})
155155

156-
it('updates an existing property in a data object', () => {
156+
it('updates an existing property in a data object', async () => {
157157
const TestComponent = {
158158
data: () => ({
159159
anObject: {
@@ -166,7 +166,7 @@ describeWithShallowAndMount('setData', mountingMethod => {
166166
render: () => {}
167167
}
168168
const wrapper = mountingMethod(TestComponent)
169-
wrapper.setData({
169+
await wrapper.setData({
170170
anObject: {
171171
propA: {
172172
prop1: 'c'
@@ -177,7 +177,7 @@ describeWithShallowAndMount('setData', mountingMethod => {
177177
expect(wrapper.vm.anObject.propA.prop1).toEqual('c')
178178
})
179179

180-
it('should append a new property to an object without removing existing properties', () => {
180+
it('should append a new property to an object without removing existing properties', async () => {
181181
const TestComponent = {
182182
data: () => ({
183183
anObject: {
@@ -190,7 +190,7 @@ describeWithShallowAndMount('setData', mountingMethod => {
190190
render: () => {}
191191
}
192192
const wrapper = mountingMethod(TestComponent)
193-
wrapper.setData({
193+
await wrapper.setData({
194194
anObject: {
195195
propA: {
196196
prop2: 'b'
@@ -238,7 +238,7 @@ describeWithShallowAndMount('setData', mountingMethod => {
238238
}
239239
})
240240
expect(wrapper.text()).toContain('bar')
241-
wrapper.setData({
241+
await wrapper.setData({
242242
nullProperty: {
243243
another: {
244244
obj: true
@@ -261,7 +261,7 @@ describeWithShallowAndMount('setData', mountingMethod => {
261261
})
262262
}
263263
const wrapper = mountingMethod(TestComponent)
264-
wrapper.setData({
264+
await wrapper.setData({
265265
items: [3]
266266
})
267267
expect(wrapper.vm.items).toEqual([3])
@@ -304,7 +304,7 @@ describeWithShallowAndMount('setData', mountingMethod => {
304304
expect(wrapper.html()).toEqual('<div>propA,propB,propC</div>')
305305
})
306306

307-
it('allows setting data of type Date synchronously', () => {
307+
it('allows setting data of type Date synchronously', async () => {
308308
const TestComponent = {
309309
template: `
310310
<div>
@@ -317,7 +317,7 @@ describeWithShallowAndMount('setData', mountingMethod => {
317317
}
318318
const testDate = new Date()
319319
const wrapper = mountingMethod(TestComponent)
320-
wrapper.setData({ selectedDate: testDate })
320+
await wrapper.setData({ selectedDate: testDate })
321321
expect(wrapper.vm.selectedDate).toEqual(testDate)
322322
})
323323
})

0 commit comments

Comments
 (0)