Type the following command to run tests.
$ npm test
A promise represents the eventual result of an asynchronous operation. The primary way of interacting with a promise is through its then
method, which registers callbacks to receive either a promise's eventual value or the reason why the promise cannot be fulfilled.
Our tests details the behavior of the then
method, providing an interoperable base which all Promises/A+ conformant promise implementations can be depended on to provide.
A promise must provide a then
method to access its current or eventual value or reason.
A promise's then
method accepts two arguments:
promise.then(onFulfilled, onRejected)
-
Both
onFulfilled
andonRejected
are optional arguments:- If
onFulfilled
is not a function, it must be ignored. - If
onRejected
is not a function, it must be ignored.
- If
-
If
onFulfilled
is a function:- it must be called after
promise
is fulfilled, withpromise
's value as its first argument. - it must not be called before
promise
is fulfilled. - it must not be called more than once.
- it must be called after
-
If
onRejected
is a function,- it must be called after
promise
is rejected, withpromise
's reason as its first argument. - it must not be called before
promise
is rejected. - it must not be called more than once.
- it must be called after
-
onFulfilled
oronRejected
must not be called until the execution context stack contains only platform code. [3.1]. -
onFulfilled
andonRejected
must be called as functions (i.e. with nothis
value). [3.2] -
then
may be called multiple times on the same promise.- If/when
promise
is fulfilled, all respectiveonFulfilled
callbacks must execute in the order of their originating calls tothen
. - If/when
promise
is rejected, all respectiveonRejected
callbacks must execute in the order of their originating calls tothen
.
- If/when
-
then
must return a promise [3.3].- If either
onFulfilled
oronRejected
returns a valuex
, run the Promise Resolution Procedure[[Resolve]](promise2, x)
. - If either
onFulfilled
oronRejected
throws an exceptione
,promise2
must be rejected withe
as the reason. - If
onFulfilled
is not a function andpromise1
is fulfilled,promise2
must be fulfilled with the same value aspromise1
. - If
onRejected
is not a function andpromise1
is rejected,promise2
must be rejected with the same reason aspromise1
.
- If either