Skip to content

Commit

Permalink
Update wrapper async mode docs (#1648)
Browse files Browse the repository at this point in the history
* docs(setvalue): update setValue documentation to reflect async mode

* docs(setselected): update setSelected docs to reflect async mode

* docs(setprops): update setProps docs to reflect async mode

* docs: update setData docs to reflect async mode

* docs(setchecked): update setChecked docs to reflect async mode

* docs(setchecked): add assertions

* docs(setdata): add whitespace to AAA

* docs(setprops): add whitespace to AAA

* docs(setselected): add assertion

* docs(setvalue): add assertions

Co-authored-by: Jordy Schreuders <3071062+99linesofcode@users.noreply.github.com>
  • Loading branch information
AtofStryker and 99linesofcode committed Aug 19, 2020
1 parent 8af56d2 commit f94a62d
Show file tree
Hide file tree
Showing 24 changed files with 208 additions and 88 deletions.
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()

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()

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')
})
```

0 comments on commit f94a62d

Please sign in to comment.