Skip to content

Commit c7b0154

Browse files
committed
Clean up some things
1 parent 26f6fa9 commit c7b0154

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

lib/test.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ function Test(title, fn) {
2525

2626
this.title = title || fnName(fn) || '[anonymous]';
2727
this.fn = isGeneratorFn(fn) ? co.wrap(fn) : fn;
28-
this.assertPromises = [];
28+
this.assertions = [];
2929
this.planCount = null;
3030
this.duration = null;
3131
this.assertError = undefined;
3232

3333
Object.defineProperty(this, 'assertCount', {
3434
enumerable: true,
3535
get: function () {
36-
return this.assertPromises.length;
36+
return this.assertions.length;
3737
}
3838
});
3939

@@ -54,7 +54,7 @@ function Test(title, fn) {
5454
module.exports = Test;
5555

5656
Test.prototype._assert = function (promise) {
57-
this.assertPromises.push(promise);
57+
this.assertions.push(promise);
5858
};
5959

6060
Test.prototype._setAssertError = function (err) {
@@ -173,23 +173,21 @@ Test.prototype.exit = function () {
173173
var self = this;
174174

175175
function checkAssertLength() {
176-
if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) {
176+
if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertions.length) {
177177
self._setAssertError(new assert.AssertionError({
178-
actual: self.assertPromises.length,
178+
actual: self.assertions.length,
179179
expected: self.planCount,
180180
message: 'Assertion count does not match planned',
181181
operator: 'plan'
182182
}));
183183

184184
self.assertError.stack = self.planStack;
185-
return false;
186185
}
187-
return true;
188186
}
189187

190188
checkAssertLength();
191189

192-
Promise.all(this.assertPromises)
190+
Promise.all(this.assertions)
193191
.catch(function (err) {
194192
self._setAssertError(err);
195193
})

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"sinon": "^1.17.2",
126126
"source-map-fixtures": "^0.3.0",
127127
"tap": "^2.2.1",
128+
"delay": "^1.2.0",
128129
"xo": "*",
129130
"zen-observable": "^0.1.6"
130131
},

test/test.js

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use strict';
22
var test = require('tap').test;
3+
var Promise = global.Promise = require('bluebird');
4+
var delay = require('delay');
35
var _ava = require('../lib/test');
46

5-
function delay(val, time) {
6-
return new Promise(function (resolve) {
7-
setTimeout(function () {
8-
resolve(val);
9-
}, time);
7+
// This is a helper some boilerplate for testing `t.throws`
8+
function delayReject(ms, message) {
9+
return delay(ms).then(function () {
10+
throw new Error(message);
1011
});
1112
}
1213

@@ -364,10 +365,10 @@ test('throws and doesNotThrow work with promises', function (t) {
364365
var asyncCalled = false;
365366
ava(function (a) {
366367
a.plan(2);
367-
a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo');
368-
a.doesNotThrow(delay(Promise.resolve().then(function () {
368+
a.throws(delayReject(10, 'foo'), 'foo');
369+
a.doesNotThrow(delay(20).then(function () {
369370
asyncCalled = true;
370-
}), 20));
371+
}));
371372
}).run().then(function (a) {
372373
t.ifError(a.assertError);
373374
t.is(a.planCount, 2);
@@ -377,10 +378,10 @@ test('throws and doesNotThrow work with promises', function (t) {
377378
});
378379
});
379380

380-
test('t.end is called when a promise passed to t.throws hasn\'t resolved yet', function (t) {
381+
test('waits for t.throws to resolve after t.end is called', function (t) {
381382
ava.cb(function (a) {
382383
a.plan(1);
383-
a.doesNotThrow(delay(Promise.resolve(), 10), 'foo');
384+
a.doesNotThrow(delay(10), 'foo');
384385
a.end();
385386
}).run().then(function (a) {
386387
t.ifError(a.assertError);
@@ -390,10 +391,10 @@ test('t.end is called when a promise passed to t.throws hasn\'t resolved yet', f
390391
});
391392
});
392393

393-
test('t.end is called when a promise passed to t.throws hasn\'t rejected yet', function (t) {
394+
test('waits for t.throws to reject after t.end is called', function (t) {
394395
ava.cb(function (a) {
395396
a.plan(1);
396-
a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo');
397+
a.throws(delayReject(10, 'foo'), 'foo');
397398
a.end();
398399
}).run().then(function (a) {
399400
t.ifError(a.assertError);
@@ -403,10 +404,10 @@ test('t.end is called when a promise passed to t.throws hasn\'t rejected yet', f
403404
});
404405
});
405406

406-
test('test returns a promise that resolves before a promise passed to t.throws resolves', function (t) {
407+
test('waits for t.throws to resolve after the promise returned from the test resolves', function (t) {
407408
ava(function (a) {
408409
a.plan(1);
409-
a.doesNotThrow(delay(Promise.resolve(), 10), 'foo');
410+
a.doesNotThrow(delay(10), 'foo');
410411
return Promise.resolve();
411412
}).run().then(function (a) {
412413
t.ifError(a.assertError);
@@ -416,10 +417,10 @@ test('test returns a promise that resolves before a promise passed to t.throws r
416417
});
417418
});
418419

419-
test('test returns a promise that resolves before a promise passed to t.throws rejects', function (t) {
420+
test('waits for t.throws to reject after the promise returned from the test resolves', function (t) {
420421
ava(function (a) {
421422
a.plan(1);
422-
a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo');
423+
a.throws(delayReject(10, 'foo'), 'foo');
423424
return Promise.resolve();
424425
}).run().then(function (a) {
425426
t.ifError(a.assertError);
@@ -433,8 +434,8 @@ test('multiple resolving and rejecting promises passed to t.throws/t.doesNotThro
433434
ava(function (a) {
434435
a.plan(6);
435436
for (var i = 0; i < 3; ++i) {
436-
a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo');
437-
a.doesNotThrow(delay(Promise.resolve(), 10), 'foo');
437+
a.throws(delayReject(10, 'foo'), 'foo');
438+
a.doesNotThrow(delay(10), 'foo');
438439
}
439440
}).run().then(function (a) {
440441
t.ifError(a.assertError);
@@ -447,8 +448,8 @@ test('multiple resolving and rejecting promises passed to t.throws/t.doesNotThro
447448
test('number of assertions matches t.plan when the test exits, but before all promises resolve another is added', function (t) {
448449
ava(function (a) {
449450
a.plan(2);
450-
a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo');
451-
a.doesNotThrow(delay(Promise.resolve(), 10), 'foo');
451+
a.throws(delayReject(10, 'foo'), 'foo');
452+
a.doesNotThrow(delay(10), 'foo');
452453
setTimeout(function () {
453454
a.throws(Promise.reject(new Error('foo')), 'foo');
454455
}, 5);
@@ -460,11 +461,11 @@ test('number of assertions matches t.plan when the test exits, but before all pr
460461
});
461462
});
462463

463-
test('number of assertions doesn\'t t.plan when the test exits, but before all promises resolve another is added', function (t) {
464+
test('number of assertions doesn\'t match plan when the test exits, but before all promises resolve another is added', function (t) {
464465
ava(function (a) {
465466
a.plan(3);
466-
a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo');
467-
a.doesNotThrow(delay(Promise.resolve(), 10), 'foo');
467+
a.throws(delayReject(10, 'foo'), 'foo');
468+
a.doesNotThrow(delay(10), 'foo');
468469
setTimeout(function () {
469470
a.throws(Promise.reject(new Error('foo')), 'foo');
470471
}, 5);

0 commit comments

Comments
 (0)