Skip to content

Commit e360cb2

Browse files
committed
test: add test case
1 parent fac185b commit e360cb2

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

packages/runtime-dom/__tests__/patchProps.spec.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { patchProp } from '../src/patchProp'
2-
import { h, nextTick, ref, render } from '../src'
2+
import { h, nextTick, ref, render, vModelCheckbox, withDirectives } from '../src'
33

44
describe('runtime-dom: props patching', () => {
55
test('basic', () => {
@@ -351,4 +351,40 @@ describe('runtime-dom: props patching', () => {
351351
expect(el.translate).toBeFalsy()
352352
expect(el.getAttribute('translate')).toBe('no')
353353
})
354+
355+
// #11647
356+
test('should not trigger input mutation when `value` is `undefined`', async () => {
357+
const fn = vi.fn()
358+
const comp = {
359+
setup() {
360+
const checked = ref()
361+
return () =>
362+
withDirectives(
363+
h('input', {
364+
type: 'checkbox',
365+
value: undefined,
366+
'onUpdate:modelValue': (value: any) => {
367+
checked.value = value
368+
},
369+
}),
370+
[[vModelCheckbox, checked.value]],
371+
)
372+
},
373+
}
374+
375+
const root = document.createElement('div')
376+
render(h(comp), root)
377+
document.body.append(root)
378+
379+
const el = root.children[0] as HTMLInputElement
380+
const observer = new MutationObserver(fn)
381+
observer.observe(el, {
382+
attributes: true,
383+
})
384+
385+
el.click()
386+
await nextTick()
387+
388+
expect(fn).toBeCalledTimes(0)
389+
})
354390
})

0 commit comments

Comments
 (0)