Socket
Socket
Sign inDemoInstall

wait-for-expect

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wait-for-expect

Wait for expectation to be true, useful for integration and end to end testing


Version published
Weekly downloads
599K
increased by7.05%
Maintainers
1
Weekly downloads
 
Created

What is wait-for-expect?

The wait-for-expect npm package is a utility for writing asynchronous tests. It allows you to wait for certain conditions to be met before proceeding with your test assertions, making it particularly useful for testing asynchronous code such as API calls, timers, and UI updates.

What are wait-for-expect's main functionalities?

Basic Usage

This feature allows you to wait for a condition to be met within a specified timeout. In this example, the test waits for the value to become 1 within 1000 milliseconds.

const waitForExpect = require('wait-for-expect');

let value = 0;
setTimeout(() => { value = 1; }, 500);

await waitForExpect(() => {
  expect(value).toBe(1);
}, 1000);

Custom Interval

This feature allows you to specify a custom interval for checking the condition. In this example, the condition is checked every 100 milliseconds within a 1000 milliseconds timeout.

const waitForExpect = require('wait-for-expect');

let value = 0;
setTimeout(() => { value = 1; }, 500);

await waitForExpect(() => {
  expect(value).toBe(1);
}, 1000, 100);

Handling Promises

This feature demonstrates how to handle promises with wait-for-expect. The test waits for the async function to resolve and then checks the condition within the specified timeout.

const waitForExpect = require('wait-for-expect');

let value = 0;
const asyncFunction = () => new Promise(resolve => setTimeout(() => { value = 1; resolve(); }, 500));

await asyncFunction();
await waitForExpect(() => {
  expect(value).toBe(1);
}, 1000);

Other packages similar to wait-for-expect

Keywords

FAQs

Package last updated on 09 Aug 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc