Permalink
Browse files

More unit tests for fromCallback and fromStandard

  • Loading branch information...
1 parent 4c6e0ed commit fe2e321fb1adaad7ee38443545aec368b63fa326 @JeffreyZhao committed Aug 1, 2012
Showing with 34 additions and 1 deletion.
  1. +34 −1 tests/jscex-async-powerpack/tests.js
@@ -265,14 +265,47 @@ exports.setupTests = function (Jscex) {
testAsync(-1, [10, 20]).start().result.should.equal(10);
});
- it("should return the first result when the callback is called asynchronously with moltiple arguments", function (done) {
+ it("should return the first result when the callback is called asynchronously with multiple arguments", function (done) {
var testAsync = Binding.fromCallback(test);
testAsync(1, [10, 20]).start().addEventListener("success", function () {
this.result.should.equal(10);
done();
});
});
+
+ it("should return the correct hash when the callback is called directly with multiple arguments", function () {
+ var testAsync = Binding.fromCallback(test, "a", "b");
+ testAsync(-1, [10, 20, 30]).start().result.should.eql({ a: 10, b: 20 });
+ });
+
+ it("should return the correct hash when the callback is called asynchronously with multiple arguments", function (done) {
+ var testAsync = Binding.fromCallback(test, "a", "b");
+ testAsync(1, [10, 20, 30]).start().addEventListener("success", function () {
+ this.result.should.eql({ a: 10, b: 20 });
+ done();
+ });
+ });
});
+
+ describe("fromStandard", function () {
+
+ it("should throw the error when the callback is called with the first argument non-undefined directly", function () {
+ var testAsync = Binding.fromStandard(test);
+ var error = {};
+ var task = testAsync(-1, [error]).start();
+ task.status.should.equal("faulted");
+ task.error.should.equal(error);
+ });
+ it("should throw the error when the callback is called with the first argument non-undefined asynchronously", function (done) {
+ var testAsync = Binding.fromStandard(test);
+ var error = {};
+ var task = testAsync(1, [error]).start().addEventListener("failure", function () {
+ this.status.should.equal("faulted");
+ this.error.should.equal(error);
+ done();
+ });
+ });
+ });
});
}

0 comments on commit fe2e321

Please sign in to comment.