Skip to content

Commit

Permalink
Unit tests for fromCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyZhao committed Jul 31, 2012
1 parent 9c58d1b commit 4c6e0ed
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion tests/jscex-async-powerpack/tests.js
Expand Up @@ -229,4 +229,50 @@ exports.setupTests = function (Jscex) {
});
});
});
}

describe("Binding", function () {

var test = function (timeout, args, callback) {
if (timeout < 0) {
callback.apply(this, args);
} else {
var _this = this;
setTimeout(function () {
callback.apply(_this, args);
}, timeout);
}
}

var Binding = Jscex.Async.Binding;

describe("fromCallback", function () {

it("should return the only result when the callback is called directly", function () {
var testAsync = Binding.fromCallback(test);
testAsync(-1, [10]).start().result.should.equal(10);
});

it("should return the only result when the callback is called asynchronously", function (done) {
var testAsync = Binding.fromCallback(test);
testAsync(1, [10]).start().addEventListener("success", function () {
this.result.should.equal(10);
done();
});
});

it("should return the first result when the callback is called directly with multiple arguments", function () {
var testAsync = Binding.fromCallback(test);
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) {
var testAsync = Binding.fromCallback(test);
testAsync(1, [10, 20]).start().addEventListener("success", function () {
this.result.should.equal(10);
done();
});
});
});

});
}

0 comments on commit 4c6e0ed

Please sign in to comment.