+56
-7
lines changedFilter options
+56
-7
lines changed Original file line number Diff line number Diff line change
@@ -363,6 +363,54 @@ describe('form-checkbox-group', () => {
363
363
wrapper.destroy()
364
364
})
365
365
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
+
366
414
it('checkboxes reflect group checked v-model', async () => {
367
415
const wrapper = mount(BFormCheckboxGroup, {
368
416
attachTo: createContainer(),
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1
1
import { htmlOrText } from '../utils/html'
2
+
import looseEqual from '../utils/loose-equal'
2
3
import normalizeSlotMixin from './normalize-slot'
3
4
import { BFormCheckbox } from '../components/form-checkbox/form-checkbox'
4
5
import { BFormRadio } from '../components/form-radio/form-radio'
@@ -70,8 +71,10 @@ export default {
70
71
checked(newVal) {
71
72
this.localChecked = newVal
72
73
},
73
-
localChecked(newVal) {
74
-
this.$emit('input', newVal)
74
+
localChecked(newVal, oldVal) {
75
+
if (!looseEqual(newVal, oldVal)) {
76
+
this.$emit('input', newVal)
77
+
}
75
78
}
76
79
},
77
80
render(h) {
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1
-
import { keys } from './object'
1
+
import { hasOwnProperty, keys } from './object'
2
2
import { isArray, isDate, isObject } from './inspect'
3
3
4
4
// Assumes both a and b are arrays!
@@ -46,10 +46,8 @@ const looseEqual = (a, b) => {
46
46
return false
47
47
}
48
48
for (const key in a) {
49
-
// eslint-disable-next-line no-prototype-builtins
50
-
const aHasKey = a.hasOwnProperty(key)
51
-
// eslint-disable-next-line no-prototype-builtins
52
-
const bHasKey = b.hasOwnProperty(key)
49
+
const aHasKey = hasOwnProperty(a, key)
50
+
const bHasKey = hasOwnProperty(b, key)
53
51
if ((aHasKey && !bHasKey) || (!aHasKey && bHasKey) || !looseEqual(a[key], b[key])) {
54
52
return false
55
53
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4