|
| 1 | +import { patchAttr, xlinkNS } from '../../src/modules/attrs' |
| 2 | + |
| 3 | +describe('attrs', () => { |
| 4 | + test('xlink attributes', () => { |
| 5 | + const el = document.createElementNS('http://www.w3.org/2000/svg', 'use') |
| 6 | + patchAttr(el, 'xlink:href', 'a', true) |
| 7 | + expect(el.getAttributeNS(xlinkNS, 'href')).toBe('a') |
| 8 | + patchAttr(el, 'xlink:href', null, true) |
| 9 | + expect(el.getAttributeNS(xlinkNS, 'href')).toBe(null) |
| 10 | + }) |
| 11 | + |
| 12 | + test('boolean attributes', () => { |
| 13 | + const el = document.createElement('input') |
| 14 | + patchAttr(el, 'readonly', true, false) |
| 15 | + expect(el.getAttribute('readonly')).toBe('') |
| 16 | + patchAttr(el, 'readonly', false, false) |
| 17 | + expect(el.getAttribute('readonly')).toBe(null) |
| 18 | + }) |
| 19 | + |
| 20 | + test('attributes', () => { |
| 21 | + const el = document.createElement('div') |
| 22 | + patchAttr(el, 'id', 'a', false) |
| 23 | + expect(el.getAttribute('id')).toBe('a') |
| 24 | + patchAttr(el, 'id', null, false) |
| 25 | + expect(el.getAttribute('id')).toBe(null) |
| 26 | + }) |
| 27 | +}) |
0 commit comments