diff options
author | Alex Early <alexander.early@gmail.com> | 2016-04-07 13:43:29 -0700 |
---|---|---|
committer | Alex Early <alexander.early@gmail.com> | 2016-04-07 13:43:29 -0700 |
commit | 0a3c1b14654ae8b58839cefdad1e8aa8cf147631 (patch) | |
tree | 2bad52cc3ee840fc0ad86bfa4afb8db3438e4361 /mocha_test | |
parent | e979953a11f66886f6d387a9e3391917b115127e (diff) | |
parent | 27e0a8bf7934d5f1a9ab7ddf3afef9bec33c54ef (diff) | |
download | async-0a3c1b14654ae8b58839cefdad1e8aa8cf147631.tar.gz |
Merge pull request #1094 from bspates/bind-after-ensure-async
Bind Context to Functions wrapped by initialParams
Diffstat (limited to 'mocha_test')
-rw-r--r-- | mocha_test/ensureAsync.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/mocha_test/ensureAsync.js b/mocha_test/ensureAsync.js new file mode 100644 index 0000000..c33e344 --- /dev/null +++ b/mocha_test/ensureAsync.js @@ -0,0 +1,32 @@ +var async = require('../lib');
+var expect = require('chai').expect;
+
+describe('ensureAsync', function() {
+ var passContext = function(cb) {
+ cb(this);
+ };
+
+ it('should propely bind context to the wrapped function', function(done) {
+
+ // call bind after wrapping with ensureAsync
+ var context = {context: "post"};
+ var postBind = async.ensureAsync(passContext);
+ postBind = postBind.bind(context);
+ postBind(function(ref) {
+ expect(ref).to.equal(context);
+ done();
+ });
+ });
+
+ it('should not override the bound context of a function when wrapping', function(done) {
+
+ // call bind before wrapping with ensureAsync
+ var context = {context: "pre"};
+ var preBind = passContext.bind(context);
+ preBind = async.ensureAsync(preBind);
+ preBind(function(ref) {
+ expect(ref).to.equal(context);
+ done();
+ });
+ });
+});
|