Skip to content

Commit de65223

Browse files
authored
Add missing await clauses (#1739)
* Add missing await clauses * Add ja and zh * Wrap await statements (CI was failing)
1 parent d7916ce commit de65223

File tree

3 files changed

+88
-76
lines changed

3 files changed

+88
-76
lines changed

Diff for: docs/guides/dom-events.md

+30-26
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44

55
### Trigger events
66

7-
The `Wrapper` exposes a `trigger` method. It can be used to trigger DOM events.
7+
The `Wrapper` exposes an async `trigger` method. It can be used to trigger DOM events.
88

99
```js
10-
const wrapper = mount(MyButton)
10+
test('triggers a click', async () => {
11+
const wrapper = mount(MyComponent)
1112

12-
wrapper.trigger('click')
13+
await wrapper.trigger('click')
14+
})
1315
```
1416

1517
You should be aware that the `find` method returns a `Wrapper` as well. Assuming `MyComponent` contains a button, the following code clicks the button.
1618

1719
```js
18-
const wrapper = mount(MyComponent)
20+
test('triggers a click', async () => {
21+
const wrapper = mount(MyComponent)
1922

20-
wrapper.find('button').trigger('click')
23+
await wrapper.find('button').trigger('click')
24+
})
2125
```
2226

2327
### Options
@@ -27,9 +31,11 @@ The `trigger` method takes an optional `options` object. The properties in the `
2731
Note that target cannot be added in the `options` object.
2832

2933
```js
30-
const wrapper = mount(MyButton)
34+
test('triggers a click', async () => {
35+
const wrapper = mount(MyComponent)
3136

32-
wrapper.trigger('click', { button: 0 })
37+
await wrapper.trigger('click', { button: 0 })
38+
})
3339
```
3440

3541
### Mouse Click Example
@@ -73,18 +79,16 @@ import YesNoComponent from '@/components/YesNoComponent'
7379
import { mount } from '@vue/test-utils'
7480
import sinon from 'sinon'
7581

76-
describe('Click event', () => {
77-
it('Click on yes button calls our method with argument "yes"', () => {
78-
const spy = sinon.spy()
79-
const wrapper = mount(YesNoComponent, {
80-
propsData: {
81-
callMe: spy
82-
}
83-
})
84-
wrapper.find('button.yes').trigger('click')
85-
86-
spy.should.have.been.calledWith('yes')
82+
it('Click on yes button calls our method with argument "yes"', async () => {
83+
const spy = sinon.spy()
84+
const wrapper = mount(YesNoComponent, {
85+
propsData: {
86+
callMe: spy
87+
}
8788
})
89+
await wrapper.find('button.yes').trigger('click')
90+
91+
spy.should.have.been.calledWith('yes')
8892
})
8993
```
9094

@@ -158,29 +162,29 @@ describe('Key event tests', () => {
158162
expect(wrapper.vm.quantity).toBe(0)
159163
})
160164

161-
it('Up arrow key increments quantity by 1', () => {
165+
it('Up arrow key increments quantity by 1', async () => {
162166
const wrapper = mount(QuantityComponent)
163-
wrapper.trigger('keydown.up')
167+
await wrapper.trigger('keydown.up')
164168
expect(wrapper.vm.quantity).toBe(1)
165169
})
166170

167-
it('Down arrow key decrements quantity by 1', () => {
171+
it('Down arrow key decrements quantity by 1', async () => {
168172
const wrapper = mount(QuantityComponent)
169173
wrapper.vm.quantity = 5
170-
wrapper.trigger('keydown.down')
174+
await wrapper.trigger('keydown.down')
171175
expect(wrapper.vm.quantity).toBe(4)
172176
})
173177

174-
it('Escape sets quantity to 0', () => {
178+
it('Escape sets quantity to 0', async () => {
175179
const wrapper = mount(QuantityComponent)
176180
wrapper.vm.quantity = 5
177-
wrapper.trigger('keydown.esc')
181+
await wrapper.trigger('keydown.esc')
178182
expect(wrapper.vm.quantity).toBe(0)
179183
})
180184

181-
it('Magic character "a" sets quantity to 13', () => {
185+
it('Magic character "a" sets quantity to 13', async () => {
182186
const wrapper = mount(QuantityComponent)
183-
wrapper.trigger('keydown', {
187+
await wrapper.trigger('keydown', {
184188
key: 'a'
185189
})
186190
expect(wrapper.vm.quantity).toBe(13)

Diff for: docs/ja/guides/dom-events.md

+29-25
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
`Wrapper``trigger` メソッドで DOM イベントをトリガすることができます。
66

77
```js
8-
const wrapper = mount(MyButton)
8+
test('triggers a click', async () => {
9+
const wrapper = mount(MyComponent)
910

10-
wrapper.trigger('click')
11+
await wrapper.trigger('click')
12+
})
1113
```
1214

1315
`find` メソッドは `mount` メソッドと同じように `Wrapper` を返します。 `MyComponent` 内に `button` があると仮定すると、以下のコードは、 `button` をクリックします。
1416

1517
```js
16-
const wrapper = mount(MyComponent)
18+
test('triggers a click', async () => {
19+
const wrapper = mount(MyComponent)
1720

18-
wrapper.find('button').trigger('click')
21+
await wrapper.find('button').trigger('click')
22+
})
1923
```
2024

2125
### オプション
@@ -25,9 +29,11 @@ wrapper.find('button').trigger('click')
2529
target を `options` オブジェクトに追加することができないことに注意してください。
2630

2731
```js
28-
const wrapper = mount(MyButton)
32+
test('triggers a click', async () => {
33+
const wrapper = mount(MyComponent)
2934

30-
wrapper.trigger('click', { button: 0 })
35+
await wrapper.trigger('click', { button: 0 })
36+
})
3137
```
3238

3339
### マウスクリックの例
@@ -68,18 +74,16 @@ import YesNoComponent from '@/components/YesNoComponent'
6874
import { mount } from '@vue/test-utils'
6975
import sinon from 'sinon'
7076

71-
describe('Click event', () => {
72-
it('Click on yes button calls our method with argument "yes"', () => {
73-
const spy = sinon.spy()
74-
const wrapper = mount(YesNoComponent, {
75-
propsData: {
76-
callMe: spy
77-
}
78-
})
79-
wrapper.find('button.yes').trigger('click')
80-
81-
spy.should.have.been.calledWith('yes')
77+
it('Click on yes button calls our method with argument "yes"', async () => {
78+
const spy = sinon.spy()
79+
const wrapper = mount(YesNoComponent, {
80+
propsData: {
81+
callMe: spy
82+
}
8283
})
84+
await wrapper.find('button.yes').trigger('click')
85+
86+
spy.should.have.been.calledWith('yes')
8387
})
8488
```
8589

@@ -150,29 +154,29 @@ describe('Key event tests', () => {
150154
expect(wrapper.vm.quantity).toBe(0)
151155
})
152156

153-
it('Cursor up sets quantity to 1', () => {
157+
it('Cursor up sets quantity to 1', async () => {
154158
const wrapper = mount(QuantityComponent)
155-
wrapper.trigger('keydown.up')
159+
await wrapper.trigger('keydown.up')
156160
expect(wrapper.vm.quantity).toBe(1)
157161
})
158162

159-
it('Cursor down reduce quantity by 1', () => {
163+
it('Cursor down reduce quantity by 1', async () => {
160164
const wrapper = mount(QuantityComponent)
161165
wrapper.vm.quantity = 5
162-
wrapper.trigger('keydown.down')
166+
await wrapper.trigger('keydown.down')
163167
expect(wrapper.vm.quantity).toBe(4)
164168
})
165169

166-
it('Escape sets quantity to 0', () => {
170+
it('Escape sets quantity to 0', async () => {
167171
const wrapper = mount(QuantityComponent)
168172
wrapper.vm.quantity = 5
169-
wrapper.trigger('keydown.esc')
173+
await wrapper.trigger('keydown.esc')
170174
expect(wrapper.vm.quantity).toBe(0)
171175
})
172176

173-
it('Magic character "a" sets quantity to 13', () => {
177+
it('Magic character "a" sets quantity to 13', async () => {
174178
const wrapper = mount(QuantityComponent)
175-
wrapper.trigger('keydown', {
179+
await wrapper.trigger('keydown', {
176180
key: 'a'
177181
})
178182
expect(wrapper.vm.quantity).toBe(13)

Diff for: docs/zh/guides/dom-events.md

+29-25
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
`Wrapper` 暴露了一个 `trigger` 方法。它可以用来触发 DOM 事件。
88

99
```js
10-
const wrapper = mount(MyButton)
10+
test('triggers a click', async () => {
11+
const wrapper = mount(MyButton)
1112

12-
wrapper.trigger('click')
13+
await wrapper.trigger('click')
14+
})
1315
```
1416

1517
你应该注意到了,`find` 方法也会返回一个 `Wrapper`。假设 `MyComponent` 包含一个按钮,下面的代码会点击这个按钮。
1618

1719
```js
18-
const wrapper = mount(MyComponent)
20+
test('triggers a click', async () => {
21+
const wrapper = mount(MyComponent)
1922

20-
wrapper.find('button').trigger('click')
23+
await wrapper.find('button').trigger('click')
24+
})
2125
```
2226

2327
### 选项
@@ -27,9 +31,11 @@ wrapper.find('button').trigger('click')
2731
注意其目标不能被添加到 `options` 对象中。
2832

2933
```js
30-
const wrapper = mount(MyButton)
34+
test('triggers a click', async () => {
35+
const wrapper = mount(MyComponent)
3136

32-
wrapper.trigger('click', { button: 0 })
37+
await wrapper.trigger('click', { button: 0 })
38+
})
3339
```
3440

3541
### 鼠标点击示例
@@ -73,18 +79,16 @@ import YesNoComponent from '@/components/YesNoComponent'
7379
import { mount } from '@vue/test-utils'
7480
import sinon from 'sinon'
7581

76-
describe('Click event', () => {
77-
it('Click on yes button calls our method with argument "yes"', () => {
78-
const spy = sinon.spy()
79-
const wrapper = mount(YesNoComponent, {
80-
propsData: {
81-
callMe: spy
82-
}
83-
})
84-
wrapper.find('button.yes').trigger('click')
85-
86-
spy.should.have.been.calledWith('yes')
82+
it('Click on yes button calls our method with argument "yes"', async () => {
83+
const spy = sinon.spy()
84+
const wrapper = mount(YesNoComponent, {
85+
propsData: {
86+
callMe: spy
87+
}
8788
})
89+
await wrapper.find('button.yes').trigger('click')
90+
91+
spy.should.have.been.calledWith('yes')
8892
})
8993
```
9094

@@ -158,29 +162,29 @@ describe('Key event tests', () => {
158162
expect(wrapper.vm.quantity).toBe(0)
159163
})
160164

161-
it('Up arrow key increments quantity by 1', () => {
165+
it('Up arrow key increments quantity by 1', async () => {
162166
const wrapper = mount(QuantityComponent)
163-
wrapper.trigger('keydown.up')
167+
await wrapper.trigger('keydown.up')
164168
expect(wrapper.vm.quantity).toBe(1)
165169
})
166170

167-
it('Down arrow key decrements quantity by 1', () => {
171+
it('Down arrow key decrements quantity by 1', async () => {
168172
const wrapper = mount(QuantityComponent)
169173
wrapper.vm.quantity = 5
170-
wrapper.trigger('keydown.down')
174+
await wrapper.trigger('keydown.down')
171175
expect(wrapper.vm.quantity).toBe(4)
172176
})
173177

174-
it('Escape sets quantity to 0', () => {
178+
it('Escape sets quantity to 0', async () => {
175179
const wrapper = mount(QuantityComponent)
176180
wrapper.vm.quantity = 5
177-
wrapper.trigger('keydown.esc')
181+
await wrapper.trigger('keydown.esc')
178182
expect(wrapper.vm.quantity).toBe(0)
179183
})
180184

181-
it('Magic character "a" sets quantity to 13', () => {
185+
it('Magic character "a" sets quantity to 13', async () => {
182186
const wrapper = mount(QuantityComponent)
183-
wrapper.trigger('keydown', {
187+
await wrapper.trigger('keydown', {
184188
key: 'a'
185189
})
186190
expect(wrapper.vm.quantity).toBe(13)

0 commit comments

Comments
 (0)