Socket
Book a DemoInstallSign in
Socket

@nichoth/dom-utils

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nichoth/dom-utils

Helpers for working with the DOM in tests

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

test

FAQs

Package last updated on 01 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts