diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 308e0f4f7..3c7e8787a 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -642,7 +642,13 @@ export default class Wrapper implements BaseWrapper { // $FlowIgnore el.selected = true // $FlowIgnore - createWrapper(el.parentElement, this.options).trigger(event) + if (el.parentElement.tagName === 'OPTGROUP') { + // $FlowIgnore + createWrapper(el.parentElement.parentElement, this.options).trigger(event) + } else { + // $FlowIgnore + createWrapper(el.parentElement, this.options).trigger(event) + } } else if (tag === 'SELECT') { throwError('wrapper.setSelected() cannot be called on select. Call it on one of its options') } else if (tag === 'INPUT' && type === 'checkbox') { diff --git a/test/resources/components/component-with-input.vue b/test/resources/components/component-with-input.vue index 12fad1655..913294d90 100644 --- a/test/resources/components/component-with-input.vue +++ b/test/resources/components/component-with-input.vue @@ -9,6 +9,15 @@ + checkbox checked diff --git a/test/specs/wrapper/setSelected.spec.js b/test/specs/wrapper/setSelected.spec.js index 86037219b..4dc9f6503 100644 --- a/test/specs/wrapper/setSelected.spec.js +++ b/test/specs/wrapper/setSelected.spec.js @@ -22,6 +22,17 @@ describeWithShallowAndMount('setSelected', (mountingMethod) => { expect(wrapper.text()).to.contain('selectA') }) + it('updates dom with select v-model for select with optgroups', () => { + const wrapper = mountingMethod(ComponentWithInput) + const options = wrapper.find('select.with-optgroups').findAll('option') + + options.at(1).setSelected() + expect(wrapper.text()).to.contain('selectB') + + options.at(0).setSelected() + expect(wrapper.text()).to.contain('selectA') + }) + it('throws error if wrapper does not contain element', () => { const wrapper = mountingMethod({ render: (h) => h('div') }) const div = wrapper.find('div')