Skip to content

Commit cae60ba

Browse files
committed
refactor: update setValue
1 parent 0628a7c commit cae60ba

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/test-utils/src/wrapper.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,7 @@ export default class Wrapper implements BaseWrapper {
744744
// $FlowIgnore
745745
const type = this.attributes().type
746746

747-
if (tagName === 'SELECT') {
748-
// $FlowIgnore
749-
this.element.value = value
750-
this.trigger('change')
751-
} else if (tagName === 'OPTION') {
747+
if (tagName === 'OPTION') {
752748
throwError(
753749
`wrapper.setValue() cannot be called on an <option> ` +
754750
`element. Use wrapper.setSelected() instead`
@@ -765,10 +761,16 @@ export default class Wrapper implements BaseWrapper {
765761
`type="radio" /> element. Use wrapper.setChecked() ` +
766762
`instead`
767763
)
768-
} else if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
764+
} else if (
765+
tagName === 'INPUT' ||
766+
tagName === 'TEXTAREA' ||
767+
tagName === 'SELECT'
768+
) {
769+
// $FlowIgnore
770+
const event = tagName === 'SELECT' ? 'change' : 'input'
769771
// $FlowIgnore
770772
this.element.value = value
771-
this.trigger('input')
773+
this.trigger(event)
772774
} else {
773775
throwError(`wrapper.setValue() cannot be called on this element`)
774776
}

test/specs/wrapper/setSelected.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ComponentWithInput from '~resources/components/component-with-input.vue'
22
import { describeWithShallowAndMount } from '~resources/utils'
33

4-
describeWithShallowAndMount.only('setSelected', mountingMethod => {
4+
describeWithShallowAndMount('setSelected', mountingMethod => {
55
it('sets element selected true', () => {
66
const wrapper = mountingMethod(ComponentWithInput)
77
const options = wrapper.find('select').findAll('option')

0 commit comments

Comments
 (0)