From 538f5778f8828cd537f7c5264a27e103ed88a774 Mon Sep 17 00:00:00 2001 From: josieusa Date: Mon, 19 Dec 2016 09:35:57 +0100 Subject: [PATCH] Follow strongloop style in test See @bajtos comment in PR #11 https://github.com/strongloop/loopback-context/pull/11#discussion_r92834319 --- test/main.test.js | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/test/main.test.js b/test/main.test.js index dc85675..29a4d16 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -108,31 +108,25 @@ describe('LoopBack Context', function() { function(done) { expect(require('async/package.json').version).to.equal('1.5.2'); LoopBackContext.runInContext(function() { - // function 1 which pulls context - var fn1 = function(cb) { - var ctx = LoopBackContext.getCurrentContext(); - expect(ctx).is.an('object'); - ctx.set('test-key', 'test-value'); - cb(); - }; - // function 2 which pulls context - var fn2 = function(cb) { - var ctx = LoopBackContext.getCurrentContext(); - expect(ctx).is.an('object'); - var testValue = ctx && ctx.get('test-key', 'test-value'); - cb(null, testValue); - }; // Trigger async waterfall callbacks - var asyncFn = function() { - async.waterfall([ - fn1, - fn2, - ], function(err, testValue) { + async.waterfall([ + function pushToContext(next) { + var ctx = LoopBackContext.getCurrentContext(); + expect(ctx).is.an('object'); + ctx.set('test-key', 'test-value'); + next(); + }, + function pullFromContext(next) { + var ctx = LoopBackContext.getCurrentContext(); + expect(ctx).is.an('object'); + var testValue = ctx && ctx.get('test-key', 'test-value'); + next(null, testValue); + }, + function verify(testValue, next) { expect(testValue).to.equal('test-value'); - done(); - }); - }; - asyncFn(); + next(); + }, + ], done); }); }); });