Promises

Introduction

promise allows to create fake promises that expose their internal state and can be resolved or rejected on demand.

Creating a promise

var promise = sinon.promise();

Creating a promise with a fake executor

var executor = sinon.fake();
var promise = sinon.promise(executor);

Creating a promise with custom executor

var promise = sinon.promise(function (resolve, reject) {
  // ...
});

Promise API

promise.status

The internal status of the promise. One of pending, resolved, rejected.

promise.resolvedValue

The promise resolved value.

promise.rejectedValue

The promise rejected value.

promise.resolve(value)

Resolves the promise with the given value. Throws if the promise is not pending.

promise.reject(value)

Rejects the promise with the given value. Throws if the promise is not pending.

© 2010–2021 Christian Johansen
Licensed under the BSD License.
https://sinonjs.org/releases/v11.1.2/promises