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

0.0.2 • Public • Published

npm

@hanbi/web-utils

@hanbi/web-utils is a small collection of utilities for reducing boilerplate in tests of primarily web-based projects.

Install

$ npm i -D @hanbi/web-utils

Usage

waitForFrame()

Uses requestAnimationFrame to wait for a single animation frame before continuing.

test('my test', async () => {
  // dom setup here
  await utils.waitForFrame();
});

waitForSelector(node, selector[, attempts])

Waits for a CSS selector to match an element in a specified node.

test('my test', async () => {
  // dom setup here
  await utils.waitForSelector(document.body, 'my-element');
});

waitForEvent(node, event)

Waits for a particular event to have been emitted by the specified node.

NOTE this should usually be called and awaited separately as you'll see in the example. This is to ensure any internal event handlers have been setup before continuing.

test('my test', async () => {
  // dom setup here
  const eventPromise = utils.waitforEvent(node, 'load');
  // do whatever should cause the 'load' event to be emitted
  const event = await eventPromise;
  // `event` is now the event which was emitted
});

License

MIT

Package Sidebar

Install

npm i @hanbi/web-utils

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

5.89 kB

Total Files

4

Last publish

Collaborators

  • 43081j