Skip to content

Commit daafacd

Browse files
authored
Update form-checkbox-group.spec.js
1 parent 156ba3b commit daafacd

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/components/form-checkbox/form-checkbox-group.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,54 @@ describe('form-checkbox-group', () => {
363363
wrapper.destroy()
364364
})
365365

366+
it('does not emit "input" event when value loosely changes', async () => {
367+
const value = ['one', 'two', 'three']
368+
const wrapper = mount(BFormCheckboxGroup, {
369+
attachTo: createContainer(),
370+
propsData: {
371+
options: value.slice(),
372+
checked: value.slice()
373+
}
374+
})
375+
expect(wrapper.classes()).toBeDefined()
376+
const checks = wrapper.findAll('input')
377+
expect(checks.length).toBe(3)
378+
expect(wrapper.vm.localChecked).toEqual(value)
379+
expect(checks.wrappers.every(c => c.find('input[type=checkbox]').exists())).toBe(true)
380+
expect(checks.at(0).element.checked).toBe(true)
381+
expect(checks.at(1).element.checked).toBe(true)
382+
expect(checks.at(2).element.checked).toBe(true)
383+
384+
expect(wrapper.emitted('input')).not.toBeDefined()
385+
386+
// Set internal value to new array reference
387+
wrapper.vm.localChecked = value.slice()
388+
await waitNT(wrapper.vm)
389+
390+
expect(wrapper.vm.localChecked).toEqual(value)
391+
expect(checks.wrappers.every(c => c.find('input[type=checkbox]').exists())).toBe(true)
392+
expect(checks.at(0).element.checked).toBe(true)
393+
expect(checks.at(1).element.checked).toBe(true)
394+
expect(checks.at(2).element.checked).toBe(true)
395+
396+
expect(wrapper.emitted('input')).not.toBeDefined()
397+
398+
// Set internal value to new array (reversed order)
399+
wrapper.vm.localChecked = value.slice().reverse()
400+
await waitNT(wrapper.vm)
401+
402+
expect(wrapper.vm.localChecked).toEqual(value.slice().reverse())
403+
expect(checks.wrappers.every(c => c.find('input[type=checkbox]').exists())).toBe(true)
404+
expect(checks.at(0).element.checked).toBe(true)
405+
expect(checks.at(1).element.checked).toBe(true)
406+
expect(checks.at(2).element.checked).toBe(true)
407+
expect(wrapper.emitted('input')).toBeDefined()
408+
expect(wrapper.emitted('input').length).toBe(1)
409+
expect(wrapper.emitted('input')[0][0]).toEqual(value.slice().reverse())
410+
411+
wrapper.destroy()
412+
})
413+
366414
it('checkboxes reflect group checked v-model', async () => {
367415
const wrapper = mount(BFormCheckboxGroup, {
368416
attachTo: createContainer(),

0 commit comments

Comments
 (0)