`)
expect(fn).toHaveBeenCalled()
})
// #1049
test('set value as-is for non string-value props', () => {
const el = document.createElement('video')
// jsdom doesn't really support video playback. srcObject in a real browser
// should default to `null`, but in jsdom it's `undefined`.
// anyway, here we just want to make sure Vue doesn't set non-string props
// to an empty string on nullish values - it should reset to its default
// value.
const initialValue = el.srcObject
const fakeObject = {}
patchProp(el, 'srcObject', null, fakeObject)
expect(el.srcObject).not.toBe(fakeObject)
patchProp(el, 'srcObject', null, null)
expect(el.srcObject).toBe(initialValue)
})
test('catch and warn prop set TypeError', () => {
const el = document.createElement('div')
Object.defineProperty(el, 'someProp', {
set() {
throw new TypeError('Invalid type')
}
})
patchProp(el, 'someProp', null, 'foo')
expect(`Failed setting prop "someProp" on
`).toHaveBeenWarnedLast()
})
// #1576
test('remove attribute when value is falsy', () => {
const el = document.createElement('div')
patchProp(el, 'id', null, '')
expect(el.hasAttribute('id')).toBe(true)
patchProp(el, 'id', null, null)
expect(el.hasAttribute('id')).toBe(false)
patchProp(el, 'id', null, '')
expect(el.hasAttribute('id')).toBe(true)
patchProp(el, 'id', null, undefined)
expect(el.hasAttribute('id')).toBe(false)
patchProp(el, 'id', null, '')
expect(el.hasAttribute('id')).toBe(true)
})
test('form attribute', () => {
const el = document.createElement('input')
patchProp(el, 'form', null, 'foo')
// non existant element
expect(el.form).toBe(null)
expect(el.getAttribute('form')).toBe('foo')
})
})