@nichoth/dom-utils
v0.0.3
Published
Helpers for working with the DOM in tests
Downloads
4
Readme
dom utils
install
npm i -D @nichoth/dom-utils
examples
Use this in tests to help with DOM manipulation.
waitFor
Wait for an element that matches a given selector. Default timeout is 5 seconds.
export function waitFor (args:{
selector?:string,
visible?:boolean,
timeout?:number
}, lambda?:()=>Element|null): Promise<Element|HTMLElement|void>
import { test } from '@nichoth/tapzero'
import * as dom from '@nichoth/dom-utils'
test('dom.waitFor', async t => {
const el = await dom.waitFor({
selector: '#foo'
})
t.equal(el!.textContent, 'bar', 'should find the element')
})
waitForText
Search for some text content. Default timeout is 5 seconds.
export function waitForText (args:{
timeout?:number,
element?:Element,
text?:string,
regex?:RegExp,
multipleTags?:boolean
}): Promise<Element|HTMLElement|void>
import { test } from '@nichoth/tapzero'
import * as dom from '@nichoth/dom-utils'
test('dom.waitForText', async t => {
// use the element we created previously
const el = await dom.waitForText({
element: document.body,
regex: /bar/
})
t.ok(el, 'should find by text content')
})