Skip to content

Commit

Permalink
Add tests for node_fn.bind
Browse files Browse the repository at this point in the history
  • Loading branch information
renato-zannon committed Dec 18, 2012
1 parent 6e7c836 commit ef38b05
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/node/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,64 @@ buster.testCase('when/node/function', {
assert.equals(value, 30);
}).always(done);
}
},

'bind': {
'should return a function': function() {
assert.isFunction(node_fn.bind(function() {}));
},

'the returned function': {
'should return a promise': function() {
var result = node_fn.bind(function() {});
assertIsPromise(result());
},

'should resolve the promise with the callback value': function(done) {
var result = node_fn.bind(function(callback) {
callback(null, 10);
});


result().then(function(value) {
assert.equals(value, 10);
}, fail).always(done);
},

'should reject the promise with the error argument': function(done) {
var error = new Error();
var result = node_fn.bind(function(callback) {
callback(error);
});


result().then(fail, function(reason) {
assert.same(reason, error);
}).always(done);
},

'should resolve the promise to an array for mult-args': function(done) {
var result = node_fn.bind(function(callback) {
callback(null, 10, 20, 30);
});

result().then(function(values) {
assert.equals(values, [10, 20, 30]);
}).always(done);
}
},

'should accept leading arguments': function(done) {
function fancySum(x, y, callback) {
callback(null, x + y);
}

var curried = node_fn.bind(fancySum, 5);

curried(10).then(function(value) {
assert.equals(value, 15);
}, fail).always(done);
},
}
});
})(require('buster'), require('../../node/function'), require('../../when'));

0 comments on commit ef38b05

Please sign in to comment.