Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Documentation for Promises-based tests.

  • Loading branch information...
commit 958dabab0409abaa2f9e484aa413f074be8cadbe 1 parent 7ab3f5c
@Yuffster authored
Showing with 26 additions and 3 deletions.
  1. +26 −3 README.md
View
29 README.md
@@ -46,10 +46,13 @@ this.expect( *subject*, *expected* )
### Asynchronous Assertions
-this.expect( *expected* )
+By passing this.expect as the callback parameter to an asynchronous function,
+describe will know to wait for the result of the operation before checking to
+see if the result matches what was expected.
+this.expect( *expected* )
-#### Example: Basic Callbacks
+#### Basic Callbacks
function addNumbersAsync(a, b, callback) {
callback(a+b);
@@ -61,7 +64,7 @@ this.expect( *expected* )
}
});
-#### Example: Node.js-style (e, data) Callbacks
+#### Node.js-style (e, data) Callbacks
function addNumbersAsync(a, b, callback) {
callback(null, a+b);
@@ -73,6 +76,26 @@ this.expect( *expected* )
}
}, { callbackMode: 'node' });
+#### Promises-style Callbacks
+
+ function addThingsPromise() {
+ var n = 0;
+ for (var i in arguments) n+=arguments[i];
+ return {
+ then: function(success, failure) {
+ success(n);
+ }
+ };
+ }
+
+ describe("promise callback style", {
+ 'promises-style addition': function() {
+ this.expect(addThingsPromise(2, 2), 4);
+ }
+ }, {
+ callbackMode: 'promises'
+ });
+
### describe.getResults
An asynchronous method. Calls back with the results of all tests described up
Please sign in to comment.
Something went wrong with that request. Please try again.