Skip to content

Instantly share code, notes, and snippets.

@domenic
Created November 10, 2011 23:26
Show Gist options
  • Save domenic/1356609 to your computer and use it in GitHub Desktop.
Save domenic/1356609 to your computer and use it in GitHub Desktop.
Sample of upcoming promise assertions module
// Say that doSomethingAsync returns a promise, and expected is the value we want it to return.
// With my library you can do the following
test("doSomethingAsync() returns expected", function () {
equal(doSomethingAsync(), expected, "As expected");
});
// Normally you would have to do
test("doSomethingAsync() returns expected", function () {
QUnit.stop();
doSomethingAsync().then(
function (result) {
equal(result, expected, "As expected");
},
function () {
ok(false, "Promise broken");
}
}).fin(QUnit.start);
}
// With a slight mashup of @kriskowal's UncommonJS testing spec with QUnit, it would look something like
test("doSomethingAsync() returns expected", function () {
return doSomethingAsync().then(function (result) {
equal(result, expected, "As expected");
});
});
@domenic
Copy link
Author

domenic commented Nov 11, 2011

Sorry, after reading the spec more carefully I see that there is automatic failure for broken promises there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment