import {createElementFromAttrs, createElementFromHTML, queryElemChildren, querySingleVisibleElem} from './dom.ts'; test('createElementFromHTML', () => { expect(createElementFromHTML('foobar').outerHTML).toEqual('foobar'); expect(createElementFromHTML('foo').outerHTML).toEqual('foo'); }); test('createElementFromAttrs', () => { const el = createElementFromAttrs('button', { id: 'the-id', class: 'cls-1 cls-2', disabled: true, checked: false, required: null, tabindex: 0, 'data-foo': 'the-data', }, 'txt', createElementFromHTML('inner')); expect(el.outerHTML).toEqual(''); }); test('querySingleVisibleElem', () => { let el = createElementFromHTML('
foo
'); expect(querySingleVisibleElem(el, 'span').textContent).toEqual('foo'); el = createElementFromHTML('
foobar
'); expect(querySingleVisibleElem(el, 'span').textContent).toEqual('bar'); el = createElementFromHTML('
foobar
'); expect(() => querySingleVisibleElem(el, 'span')).toThrowError('Expected exactly one visible element'); }); test('queryElemChildren', () => { const el = createElementFromHTML('
ab
'); const children = queryElemChildren(el, '.a'); expect(children.length).toEqual(1); });