patchAttrs.spec.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { patchProp } from '../src/patchProp'
  2. import { xlinkNS } from '../src/modules/attrs'
  3. describe('runtime-dom: attrs patching', () => {
  4. test('xlink attributes', () => {
  5. const el = document.createElementNS('http://www.w3.org/2000/svg', 'use')
  6. patchProp(el, 'xlink:href', null, 'a', true)
  7. expect(el.getAttributeNS(xlinkNS, 'href')).toBe('a')
  8. patchProp(el, 'xlink:href', 'a', null, true)
  9. expect(el.getAttributeNS(xlinkNS, 'href')).toBe(null)
  10. })
  11. test('boolean attributes', () => {
  12. const el = document.createElement('input')
  13. patchProp(el, 'readonly', null, true)
  14. expect(el.getAttribute('readonly')).toBe('')
  15. patchProp(el, 'readonly', true, false)
  16. expect(el.getAttribute('readonly')).toBe(null)
  17. })
  18. test('attributes', () => {
  19. const el = document.createElement('div')
  20. patchProp(el, 'foo', null, 'a')
  21. expect(el.getAttribute('foo')).toBe('a')
  22. patchProp(el, 'foo', 'a', null)
  23. expect(el.getAttribute('foo')).toBe(null)
  24. })
  25. // #949
  26. test('onxxx but non-listener attributes', () => {
  27. const el = document.createElement('div')
  28. patchProp(el, 'onwards', null, 'a')
  29. expect(el.getAttribute('onwards')).toBe('a')
  30. patchProp(el, 'onwards', 'a', null)
  31. expect(el.getAttribute('onwards')).toBe(null)
  32. })
  33. })