npm.io
1.0.1 • Published 7 years ago

fp-future

Licence
MIT
Version
1.0.1
Deps
0
Size
5 kB
Vulns
0
Weekly
0
Stars
6

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);
});