Created
November 10, 2011 23:26
-
-
Save domenic/1356609 to your computer and use it in GitHub Desktop.
Sample of upcoming promise assertions module
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
// 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"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, after reading the spec more carefully I see that there is automatic failure for broken promises there too.