|
| 1 | +import {apply, isPolyfilled, isSupported, replaceChildren} from '../lib/element-replacechildren.js' |
| 2 | + |
| 3 | +describe('replaceChildren', () => { |
| 4 | + it('has standard isSupported, isPolyfilled, apply API', () => { |
| 5 | + expect(isSupported).to.be.a('function') |
| 6 | + expect(isPolyfilled).to.be.a('function') |
| 7 | + expect(apply).to.be.a('function') |
| 8 | + expect(isSupported()).to.be.a('boolean') |
| 9 | + expect(isPolyfilled()).to.equal(false) |
| 10 | + }) |
| 11 | + |
| 12 | + it('replaces all Element children with given nodes', async () => { |
| 13 | + const el = document.createElement('div') |
| 14 | + // eslint-disable-next-line github/no-inner-html, github/unescaped-html-literal |
| 15 | + el.innerHTML = '<p></p><span>Hi</span>' |
| 16 | + replaceChildren.call(el, 'X') |
| 17 | + // eslint-disable-next-line github/no-inner-html |
| 18 | + expect(el.innerHTML).to.eql('X') |
| 19 | + const s = document.createElement('span') |
| 20 | + // eslint-disable-next-line github/unescaped-html-literal |
| 21 | + s.textContent = '<foo>' |
| 22 | + replaceChildren.call(el, s) |
| 23 | + // eslint-disable-next-line github/no-inner-html, github/unescaped-html-literal |
| 24 | + expect(el.innerHTML).to.eql('<span><foo></span>') |
| 25 | + }) |
| 26 | +}) |
0 commit comments