Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/43081j/hanbi-web-utils
A small collection of utilities for testing in web projects
https://github.com/43081j/hanbi-web-utils
Last synced: about 2 months ago
JSON representation
A small collection of utilities for testing in web projects
- Host: GitHub
- URL: https://github.com/43081j/hanbi-web-utils
- Owner: 43081j
- Created: 2021-06-27T14:10:12.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-07-27T08:52:47.000Z (over 3 years ago)
- Last Synced: 2024-10-12T03:17:35.254Z (3 months ago)
- Language: TypeScript
- Size: 93.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![npm](https://img.shields.io/npm/v/@hanbi/web-utils)](https://www.npmjs.com/package/@hanbi/web-utils)
# @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.```ts
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.
```ts
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.```ts
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