2020-04-11 03:37:30 +08:00
|
|
|
import { patchProp } from '../src/patchProp'
|
|
|
|
import { xlinkNS } from '../src/modules/attrs'
|
2020-03-17 06:46:01 +08:00
|
|
|
|
2020-04-11 03:23:01 +08:00
|
|
|
describe('runtime-dom: attrs patching', () => {
|
2020-03-17 06:46:01 +08:00
|
|
|
test('xlink attributes', () => {
|
|
|
|
const el = document.createElementNS('http://www.w3.org/2000/svg', 'use')
|
2020-04-10 23:57:07 +08:00
|
|
|
patchProp(el, 'xlink:href', null, 'a', true)
|
2020-03-17 06:46:01 +08:00
|
|
|
expect(el.getAttributeNS(xlinkNS, 'href')).toBe('a')
|
2020-04-10 23:57:07 +08:00
|
|
|
patchProp(el, 'xlink:href', 'a', null, true)
|
2020-03-17 06:46:01 +08:00
|
|
|
expect(el.getAttributeNS(xlinkNS, 'href')).toBe(null)
|
|
|
|
})
|
|
|
|
|
2021-08-11 22:53:54 +08:00
|
|
|
test('textContent attributes /w svg', () => {
|
|
|
|
const el = document.createElementNS('http://www.w3.org/2000/svg', 'use')
|
|
|
|
patchProp(el, 'textContent', null, 'foo', true)
|
|
|
|
expect(el.attributes.length).toBe(0)
|
|
|
|
expect(el.innerHTML).toBe('foo')
|
|
|
|
})
|
|
|
|
|
2020-03-17 06:46:01 +08:00
|
|
|
test('boolean attributes', () => {
|
|
|
|
const el = document.createElement('input')
|
2020-04-10 23:57:07 +08:00
|
|
|
patchProp(el, 'readonly', null, true)
|
2020-03-17 06:46:01 +08:00
|
|
|
expect(el.getAttribute('readonly')).toBe('')
|
2020-04-10 23:57:07 +08:00
|
|
|
patchProp(el, 'readonly', true, false)
|
2020-03-17 06:46:01 +08:00
|
|
|
expect(el.getAttribute('readonly')).toBe(null)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('attributes', () => {
|
|
|
|
const el = document.createElement('div')
|
2020-04-10 23:57:07 +08:00
|
|
|
patchProp(el, 'foo', null, 'a')
|
|
|
|
expect(el.getAttribute('foo')).toBe('a')
|
|
|
|
patchProp(el, 'foo', 'a', null)
|
|
|
|
expect(el.getAttribute('foo')).toBe(null)
|
|
|
|
})
|
|
|
|
|
|
|
|
// #949
|
|
|
|
test('onxxx but non-listener attributes', () => {
|
|
|
|
const el = document.createElement('div')
|
|
|
|
patchProp(el, 'onwards', null, 'a')
|
|
|
|
expect(el.getAttribute('onwards')).toBe('a')
|
|
|
|
patchProp(el, 'onwards', 'a', null)
|
|
|
|
expect(el.getAttribute('onwards')).toBe(null)
|
2020-03-17 06:46:01 +08:00
|
|
|
})
|
|
|
|
})
|