Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wrapper async mode docs #1648

Merged
merged 10 commits into from
Aug 19, 2020
11 changes: 8 additions & 3 deletions docs/api/wrapper/setChecked.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ Sets checked value for input element of type checkbox or radio and updates `v-mo
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
const radioInput = wrapper.find('input[type="radio"]')
radioInput.setChecked()
test('setChecked demo', async () => {
const wrapper = mount(Foo)
const radioInput = wrapper.find('input[type="radio"]')

await radioInput.setChecked()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(wrapper.find('input[type="radio"]').element.checked).toBeTruthy()

On that note, is there something wrong with using a let here, allowing Jest / VueTestUtils to update the radio button and allowing us to replace the duplicate wrapper.find('input[type="radio"]') call with radioInput instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(wrapper.find('input[type="radio"]').element.checked).toBeTruthy()

On that note, is there something wrong with using a let here, allowing Jest / VueTestUtils to update the radio button and allowing us to replace the duplicate wrapper.find('input[type="radio"]') call with radioInput instead?

I don't think there is an issue with using let over const here. I think it depends on the strategy we want to go about from a documentation standpoint, which I'll describe a bit more here. If we ultimately wind up adding the assertions, we can use let, but for example use, duplication isn't necessarily a bad thing 😄 .


expect(radioInput.element.checked).toBeTruthy()
})
```

- **Note:**
Expand Down
10 changes: 7 additions & 3 deletions docs/api/wrapper/setData.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ setData works by recursively calling Vue.set.
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
wrapper.setData({ foo: 'bar' })
expect(wrapper.vm.foo).toBe('bar')
test('setData demo', async () => {
const wrapper = mount(Foo)

await wrapper.setData({ foo: 'bar' })

expect(wrapper.vm.foo).toBe('bar')
})
```
10 changes: 7 additions & 3 deletions docs/api/wrapper/setProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ Sets `Wrapper` `vm` props and forces update.
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
wrapper.setProps({ foo: 'bar' })
expect(wrapper.vm.foo).toBe('bar')
test('setProps demo', async () => {
const wrapper = mount(Foo)

await wrapper.setProps({ foo: 'bar' })

expect(wrapper.vm.foo).toBe('bar')
})
```

You can also pass a `propsData` object, which will initialize the Vue instance with passed values.
Expand Down
10 changes: 7 additions & 3 deletions docs/api/wrapper/setSelected.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ Selects an option element and updates `v-model` bound data.
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
const options = wrapper.find('select').findAll('option')
test('setSelected demo', async () => {
const wrapper = mount(Foo)
const options = wrapper.find('select').findAll('option')

options.at(1).setSelected()
await options.at(1).setSelected()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(wrapper.find('option:checked').element.value).toBe('bar')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this one better, too.


expect(wrapper.find('option:checked').element.value).toBe('bar')
})
```

- **Note:**
Expand Down
27 changes: 19 additions & 8 deletions docs/api/wrapper/setValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,28 @@ Sets value of a text-control input or select element and updates `v-model` bound
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
test('setValue demo', async () => {
const wrapper = mount(Foo)

const textInput = wrapper.find('input[type="text"]')
textInput.setValue('some value')
const textInput = wrapper.find('input[type="text"]')
await textInput.setValue('some value')

const select = wrapper.find('select')
select.setValue('option value')
expect(wrapper.find('input[type="text"]').element.value).toBe('some value')

// requires <select multiple>
const multiselect = wrapper.find('select')
multiselect.setValue(['value1', 'value3'])
const select = wrapper.find('select')
await select.setValue('option value')

expect(wrapper.find('select').element.value).toBe('option value')

// requires <select multiple>
const multiselect = wrapper.find('select')
await multiselect.setValue(['value1', 'value3'])

const selectedOptions = Array.from(multiselect.element.selectedOptions).map(
o => o.value
)
expect(selectedOptions).toEqual(['value1', 'value3'])
})
```

- **Note:**
Expand Down
6 changes: 4 additions & 2 deletions docs/guides/common-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ describe('ParentComponent', () => {
You can directly manipulate the state of the component using the `setData` or `setProps` method on the wrapper:

```js
wrapper.setData({ count: 10 })
it('manipulates state', async () => {
await wrapper.setData({ count: 10 })

wrapper.setProps({ foo: 'bar' })
await wrapper.setProps({ foo: 'bar' })
})
```

### Mocking Props
Expand Down
11 changes: 8 additions & 3 deletions docs/ja/api/wrapper/setChecked.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ checkbox 型もしくは radio 型の input 要素の checked の値をセット
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
const radioInput = wrapper.find('input[type="radio"]')
radioInput.setChecked()
test('setChecked demo', async () => {
const wrapper = mount(Foo)
const radioInput = wrapper.find('input[type="radio"]')

await radioInput.setChecked()

expect(radioInput.element.checked).toBeTruthy()
})
```

- **注:**
Expand Down
10 changes: 7 additions & 3 deletions docs/ja/api/wrapper/setData.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ setData は再帰的に Vue.set を実行することで動作します。
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
wrapper.setData({ foo: 'bar' })
expect(wrapper.vm.foo).toBe('bar')
test('setData demo', async () => {
const wrapper = mount(Foo)

await wrapper.setData({ foo: 'bar' })

expect(wrapper.vm.foo).toBe('bar')
})
```
10 changes: 7 additions & 3 deletions docs/ja/api/wrapper/setProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
wrapper.setProps({ foo: 'bar' })
expect(wrapper.vm.foo).toBe('bar')
test('setProps demo', async () => {
const wrapper = mount(Foo)

await wrapper.setProps({ foo: 'bar' })

expect(wrapper.vm.foo).toBe('bar')
})
```

渡された値で Vue インスタンス を初期化する `propsData` オブジェクトを渡すことができます。
Expand Down
10 changes: 7 additions & 3 deletions docs/ja/api/wrapper/setSelected.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ option 要素を選択します。そして、 `v-model` に束縛されてい
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
const options = wrapper.find('select').findAll('option')
test('setSelected demo', async () => {
const wrapper = mount(Foo)
const options = wrapper.find('select').findAll('option')

options.at(1).setSelected()
await options.at(1).setSelected()

expect(wrapper.find('option:checked').element.value).toBe('bar')
})
```

- **注:**
Expand Down
27 changes: 19 additions & 8 deletions docs/ja/api/wrapper/setValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,28 @@ text コントロールの input 要素の 値をセットします。そして
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
test('setValue demo', async () => {
const wrapper = mount(Foo)

const textInput = wrapper.find('input[type="text"]')
textInput.setValue('some value')
const textInput = wrapper.find('input[type="text"]')
await textInput.setValue('some value')

const select = wrapper.find('select')
select.setValue('option value')
expect(wrapper.find('input[type="text"]').element.value).toBe('some value')

// requires <select multiple>
const multiselect = wrapper.find('select')
multiselect.setValue(['value1', 'value3'])
const select = wrapper.find('select')
await select.setValue('option value')

expect(wrapper.find('select').element.value).toBe('option value')

// requires <select multiple>
const multiselect = wrapper.find('select')
await multiselect.setValue(['value1', 'value3'])

const selectedOptions = Array.from(multiselect.element.selectedOptions).map(
o => o.value
)
expect(selectedOptions).toEqual(['value1', 'value3'])
})
```

- **注:**
Expand Down
6 changes: 4 additions & 2 deletions docs/ja/guides/common-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ expect(wrapper.emitted().foo[1]).toEqual([123])
ラッパの `setData` メソッドまたは `setProps` メソッドを使って、コンポーネントの状態を直接操作することができます。:

```js
wrapper.setData({ count: 10 })
it('manipulates state', async () => {
await wrapper.setData({ count: 10 })

wrapper.setProps({ foo: 'bar' })
await wrapper.setProps({ foo: 'bar' })
})
```

### プロパティをモックする
Expand Down
11 changes: 8 additions & 3 deletions docs/ru/api/wrapper/setChecked.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
const radioInput = wrapper.find('input[type="radio"]')
radioInput.setChecked()
test('setChecked demo', async () => {
const wrapper = mount(Foo)
const radioInput = wrapper.find('input[type="radio"]')

await radioInput.setChecked()

expect(radioInput.element.checked).toBeTruthy()
})
```

- **Примечание:**
Expand Down
10 changes: 7 additions & 3 deletions docs/ru/api/wrapper/setData.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ setData работает путём слияния существующих св
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
wrapper.setData({ foo: 'bar' })
expect(wrapper.vm.foo).toBe('bar')
test('setData demo', async () => {
const wrapper = mount(Foo)

await wrapper.setData({ foo: 'bar' })

expect(wrapper.vm.foo).toBe('bar')
})
```
10 changes: 7 additions & 3 deletions docs/ru/api/wrapper/setProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
wrapper.setProps({ foo: 'bar' })
expect(wrapper.vm.foo).toBe('bar')
test('setProps demo', async () => {
const wrapper = mount(Foo)

await wrapper.setProps({ foo: 'bar' })

expect(wrapper.vm.foo).toBe('bar')
})
```

Вы также можете передать объект `propsData`, который инициализирует экземпляр Vue с переданными значениями.
Expand Down
10 changes: 7 additions & 3 deletions docs/ru/api/wrapper/setSelected.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
const options = wrapper.find('select').findAll('option')
test('setSelected demo', async () => {
const wrapper = mount(Foo)
const options = wrapper.find('select').findAll('option')

options.at(1).setSelected()
await options.at(1).setSelected()

expect(wrapper.find('option:checked').element.value).toBe('bar')
})
```

- **Примечание:**
Expand Down
27 changes: 19 additions & 8 deletions docs/ru/api/wrapper/setValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,28 @@
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
test('setValue demo', async () => {
const wrapper = mount(Foo)

const textInput = wrapper.find('input[type="text"]')
textInput.setValue('some value')
const textInput = wrapper.find('input[type="text"]')
await textInput.setValue('some value')

const select = wrapper.find('select')
select.setValue('option value')
expect(wrapper.find('input[type="text"]').element.value).toBe('some value')

// требует <select multiple>
const multiselect = wrapper.find('select')
multiselect.setValue(['value1', 'value3'])
const select = wrapper.find('select')
await select.setValue('option value')

expect(wrapper.find('select').element.value).toBe('option value')

// requires <select multiple>
const multiselect = wrapper.find('select')
await multiselect.setValue(['value1', 'value3'])

const selectedOptions = Array.from(multiselect.element.selectedOptions).map(
o => o.value
)
expect(selectedOptions).toEqual(['value1', 'value3'])
})
```

- **Примечание:**
Expand Down
6 changes: 4 additions & 2 deletions docs/ru/guides/common-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ describe('ParentComponent', () => {
Вы можете напрямую манипулировать состоянием компонента с помощью методов `setData` или `setProps` на обёртке:

```js
wrapper.setData({ count: 10 })
it('manipulates state', async () => {
await wrapper.setData({ count: 10 })

wrapper.setProps({ foo: 'bar' })
await wrapper.setProps({ foo: 'bar' })
})
```

### Моки входных параметров
Expand Down
11 changes: 8 additions & 3 deletions docs/zh/api/wrapper/setChecked.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
const radioInput = wrapper.find('input[type="radio"]')
radioInput.setChecked()
test('setChecked demo', async () => {
const wrapper = mount(Foo)
const radioInput = wrapper.find('input[type="radio"]')

await radioInput.setChecked()

expect(radioInput.element.checked).toBeTruthy()
})
```

- **注意:**
Expand Down
10 changes: 7 additions & 3 deletions docs/zh/api/wrapper/setData.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
wrapper.setData({ foo: 'bar' })
expect(wrapper.vm.foo).toBe('bar')
test('setData demo', async () => {
const wrapper = mount(Foo)

await wrapper.setData({ foo: 'bar' })

expect(wrapper.vm.foo).toBe('bar')
})
```