Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Mini-ghost committed Aug 19, 2024
1 parent fac185b commit 217dafc
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion packages/runtime-dom/__tests__/patchProps.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { patchProp } from '../src/patchProp'
import { h, nextTick, ref, render } from '../src'
import {
h,
nextTick,
ref,
render,
vModelCheckbox,
withDirectives,
} from '../src'

describe('runtime-dom: props patching', () => {
test('basic', () => {
Expand Down Expand Up @@ -351,4 +358,40 @@ describe('runtime-dom: props patching', () => {
expect(el.translate).toBeFalsy()
expect(el.getAttribute('translate')).toBe('no')
})

// #11647
test('should not trigger input mutation when `value` is `undefined`', async () => {
const fn = vi.fn()
const comp = {
setup() {
const checked = ref()
return () =>
withDirectives(
h('input', {
type: 'checkbox',
value: undefined,
'onUpdate:modelValue': (value: any) => {
checked.value = value
},
}),
[[vModelCheckbox, checked.value]],
)
},
}

const root = document.createElement('div')
render(h(comp), root)
document.body.append(root)

const el = root.children[0] as HTMLInputElement
const observer = new MutationObserver(fn)
observer.observe(el, {
attributes: true,
})

el.click()
await nextTick()

expect(fn).toBeCalledTimes(0)
})
})

0 comments on commit 217dafc

Please sign in to comment.