Skip to content

Commit

Permalink
Follow strongloop style in test
Browse files Browse the repository at this point in the history
  • Loading branch information
josieusa committed Dec 19, 2016
1 parent c0a70eb commit 538f577
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 538f577

Please sign in to comment.