Skip to content

Commit

Permalink
More unit tests for fromCallback and fromStandard
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyZhao committed Aug 1, 2012
1 parent 4c6e0ed commit fe2e321
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/jscex-async-powerpack/tests.js
Expand Up @@ -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.