Skip to content

Commit

Permalink
use same doneCalled trick for the other treatment api tests and a ;
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Jan 6, 2016
1 parent e22c9bf commit 71f7854
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/treatments.js
Expand Up @@ -30,7 +30,7 @@ function storage (env, ctx) {
});
} else {
upsert(objOrArray, function upserted (err, docs) {
done(err, docs)
done(err, docs);
});
}

Expand Down
14 changes: 11 additions & 3 deletions tests/api.treatments.test.js
Expand Up @@ -46,7 +46,6 @@ describe('Treatment API', function ( ) {
if (!doneCalled) { done(); }

doneCalled = true;

});

self.ctx.treatments().remove({ }, function ( ) {
Expand Down Expand Up @@ -76,6 +75,7 @@ describe('Treatment API', function ( ) {
});

it('post a treatment array', function (done) {
var doneCalled = false;

self.ctx.bus.on('data-loaded', function dataWasLoaded ( ) {
self.ctx.ddata.treatments.length.should.equal(3);
Expand All @@ -90,7 +90,10 @@ describe('Treatment API', function ( ) {
self.ctx.ddata.treatments[1].insulin.should.equal(2);
self.ctx.ddata.treatments[2].carbs.should.equal(30);

done();
//if travis is slow the 2 posts take long enough that 2 data-loaded events are emitted
if (!doneCalled) { done(); }

doneCalled = true;
});

self.ctx.treatments().remove({ }, function ( ) {
Expand All @@ -111,11 +114,16 @@ describe('Treatment API', function ( ) {
});

it('post a treatment array and dedupe', function (done) {
var doneCalled = false;

self.ctx.bus.on('data-loaded', function dataWasLoaded ( ) {
self.ctx.ddata.treatments.length.should.equal(3);
self.ctx.ddata.treatments[0].mgdl.should.equal(100);
done();

//if travis is slow the 2 posts take long enough that 2 data-loaded events are emitted
if (!doneCalled) { done(); }

doneCalled = true;
});

self.ctx.treatments().remove({ }, function ( ) {
Expand Down

0 comments on commit 71f7854

Please sign in to comment.