WHAT’S IN THIS CHAPTER?
- Using and testing Promises
- Understanding Promise states and fates
- Constructing Promises
- Testing a Promise-wrapped XMLHttpRequest
- Chaining Promises
- How “Deferred” libraries handle advanced scenarios in Promise testing
- A caution about jQuery promises
WROX.COM CODE DOWNLOADS FOR THIS CHAPTER
The wrox.com code downloads for this chapter are found at
The last chapter illustrated how to code and test (or, more correctly, test and code) the Callback Pattern. In the main example,
Promise object. If you must support older browsers, polyfills are available.
UNDERSTANDING PROMISES THROUGH UNIT TESTS
Promise is an object that encapsulates an asynchronous operation and what to do upon its eventual outcome. When the operation completes, a callback encapsulated in the
Promise will be invoked. Actually, there can be two callbacks: one for success and one for failure. (The first callback does not ...