Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fp-future

menduz27.8kMIT1.0.1TypeScript support: included

A Future is a placeholder object for a value that may not yet exist

readme

A Future is a placeholder object for a value that may not yet exist

Installation

npm install fp-future

FP Future library

It is useful for blackbox testing without weird injections and other things.

it("executes the callback", async () => {
  const somethingToBeResolved = future();

  entity.onClick(event => {
    somethingToBeResolved.resolve(event);
  });

  const nonce = Math.random();

  setTimeout(() => somethingToBeResolved.reject(new Error("timeout")), 1000);

  entityEngine.triggerClick(nonce);

  const receivedNonce = await somethingToBeResolved;

  expect(receivedNonce).toEq(nonce);
});