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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 21 additions & 25 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 6 additions & 6 deletions
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
})

0 commit comments

Comments
 (0)