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

Fix wrapper.setSelected() to work on select with optgroups #715

Merged
merged 3 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/server-test-utils/dist/vue-server-test-utils.js

Large diffs are not rendered by default.

25 changes: 19 additions & 6 deletions packages/test-utils/dist/vue-test-utils.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
9 changes: 9 additions & 0 deletions test/resources/components/component-with-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<option value="selectB"></option>
<option value="selectC"></option>
</select>
<select v-model="selectVal" class="with-optgroups">
<optgroup label="Group1">
<option value="selectA"></option>
<option value="selectB"></option>
</optgroup>
<optgroup label="Group2">
<option value="selectC"></option>
</optgroup>
</select>
<label id="label-el"></label>

<span class="checkboxResult" v-if="checkboxVal">checkbox checked</span>
Expand Down
11 changes: 11 additions & 0 deletions test/specs/wrapper/setSelected.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down