@nichoth/dom-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

dom utils

tests Socket Badge module types license

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')
})

Readme

Keywords

Package Sidebar

Install

npm i @nichoth/dom-utils

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

687 kB

Total Files

21

Last publish

Collaborators

  • nichoth