Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
layout: page | ||
title: Promises - Sinon.JS | ||
breadcrumb: promises | ||
--- | ||
|
||
### Introduction | ||
|
||
`promise` allows to create fake promises that expose their internal state and can be resolved or rejected on demand. | ||
|
||
### Creating a promise | ||
|
||
```js | ||
var promise = sinon.promise(); | ||
``` | ||
|
||
#### Creating a promise with a fake executor | ||
|
||
```js | ||
var executor = sinon.fake(); | ||
var promise = sinon.promise(executor); | ||
``` | ||
|
||
#### Creating a promise with custom executor | ||
|
||
```js | ||
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`. |