-
Notifications
You must be signed in to change notification settings - Fork 664
Closed
Labels
Description
Simulating selecting radio buttons doesn't seem to be reflected in the model:
wrapperDeep.find('input[type="radio"]').element.selected = true;
Full code with the reproduced example:
https://github.com/folmert/vue-test-utils-jest-example
RadioGroup.vue:
<template>
<div>
<label><input v-model="folder" type="radio" name="folder" value="new"> New</label>
<label><input v-model="folder" type="radio" name="folder" value="existing"> Existing</label>
<div class="selected">Selected: {{folder}}</div>
</div>
</template>
<script>
export default {
name: 'RadioGroup',
data () {
return {
folder: ''
}
}
}
</script>
RadioGroup.spec.js:
import {mount} from 'vue-test-utils';
import RadioGroup from '@/components/RadioGroup';
describe('RadioGroup', () => {
let wrapperDeep;
beforeEach(() => {
wrapperDeep = mount(RadioGroup, {});
});
// works
it('changes data according to the changed folder data', () => {
wrapperDeep.setData({folder: 'existing'});
expect(wrapperDeep.find('.selected').text()).toBe('Selected: existing');
});
// doesn't work
it('changes data according to the selected folder option', () => {
wrapperDeep.find('input[type="radio"][value="existing"]').element.selected = true;
expect(wrapperDeep.find('.selected').text()).toBe('Selected: existing');
});
});
yarn test
result:
RadioGroup
√ renders changed data according to the changed folder data (38ms)
× renders changed data according to the selected folder option (8ms)
Expected value to be (using ===):
"Selected: existing"
Received:
"Selected:"
eddyerburgh, vjcagay, birol, chriszrc, bachbach and 2 more