diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a9628ce3a..0f88c6962 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -82,7 +82,7 @@ The default test script will do the following: lint with ESLint -> type check wi - **`create-instance`**: private package that creates an instance and applies mounting options. - - **`shared`**: private package that contains utilities used by the other packzges. + - **`shared`**: private package that contains utilities used by the other packages. - **`scripts`**: contains build-related scripts and configuration files. In most cases you don't need to touch them. diff --git a/docs/api/wrapper/setValue.md b/docs/api/wrapper/setValue.md index e55a91066..c231e0ecd 100644 --- a/docs/api/wrapper/setValue.md +++ b/docs/api/wrapper/setValue.md @@ -1,6 +1,6 @@ ## setValue(value) -Sets value of a text-control input element and updates `v-model` bound data. +Sets value of a text-control input or select element and updates `v-model` bound data. - **Arguments:** - `{any} value` @@ -12,15 +12,26 @@ import { mount } from '@vue/test-utils' import Foo from './Foo.vue' const wrapper = mount(Foo) + const input = wrapper.find('input[type="text"]') input.setValue('some value') + +const select = wrapper.find('select') +select.setValue('option value') ``` - **Note:** -`textInput.setValue(value)` is an alias of the following code. + - `textInput.setValue(value)` is an alias of the following code. -```js -textInput.element.value = value -textInput.trigger('input') -``` + ```js + textInput.element.value = value + textInput.trigger('input') + ``` + + - `select.setValue(value)` is an alias of the following code. + + ```js + select.element.value = value + select.trigger('change') + ``` diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 6b13b2005..63936401f 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -697,8 +697,12 @@ export default class Wrapper implements BaseWrapper { const type = this.attributes().type if (tagName === 'SELECT') { + // $FlowIgnore + this.element.value = value + this.trigger('change') + } else if (tagName === 'OPTION') { throwError( - `wrapper.setValue() cannot be called on a element. Use wrapper.setSelected() instead' - shouldThrowErrorOnElement('select', message) + 'wrapper.setValue() cannot be called on an