@socketsupply/test-dom

Tools for testing in a browser environment


Keywords
dom, test
License
ISC
Install
npm install @socketsupply/test-dom@0.4.1

Documentation

test dom

We had previously used @testing-library/dom & @testing-library/user-event.

Here we implement similar functionality but with less code.

install

npm i -D @socketsupply/test-dom

use

commonjs

const dom = require('@socketsupply/test-dom')

esm

import dom from '@socketsupply/test-dom'

example

waitForText

const el = await dom.waitForText({
    // `dom.qs` is a convenience function, short for `document.querySelector`
    element: dom.qs('.css-query'),
    regex: /foo/
})

waitFor

const el = await dom.waitFor({
    // css query here
    selector: 'p'
})

qs

// document.querySelector
const el = dom.qs('#my-css-id')

qsa

// document.querySelectorAll
const elements = dom.qsa('.my-css-class')

click

Automate click events

const element = dom.qs('#example')
dom.click(element)

test

npm test