From 3d171ff12b127d23333c97568ef0128c242d7ebb Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 12:27:22 -0800 Subject: [PATCH 01/10] Add tests to confirm that assertions on promises are delt with correctly. Refs #309. --- test/test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test.js b/test/test.js index 51e75e866..7ea62bc96 100644 --- a/test/test.js +++ b/test/test.js @@ -2,6 +2,14 @@ var test = require('tap').test; var _ava = require('../lib/test'); +function delay(val, time) { + return new Promise(function (resolve) { + setTimeout(function () { + resolve(val); + }, time); + }); +} + function ava() { var t = _ava.apply(null, arguments); t.metadata = {callback: false}; @@ -351,3 +359,20 @@ test('skipped assertions count towards the plan', function (t) { t.end(); }); }); + +test('throws and doesNotThrow work with promises', function (t) { + var asyncCalled = false; + ava(function (a) { + a.plan(2); + a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); + a.doesNotThrow(delay(Promise.resolve().then(function () { + asyncCalled = true; + }), 20)); + }).run().then(function (a) { + t.ifError(a.assertError); + t.is(a.planCount, 2); + t.is(a.assertCount, 2); + t.is(asyncCalled, true); + t.end(); + }); +}); From c87384517c5f3cb371155ee6cfa8099e485468d8 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 12:28:14 -0800 Subject: [PATCH 02/10] Fix assertions that use promises. Fixes #309. --- lib/test.js | 95 +++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/lib/test.js b/lib/test.js index 0cb9aea8b..78ca61c7a 100644 --- a/lib/test.js +++ b/lib/test.js @@ -25,11 +25,18 @@ function Test(title, fn) { this.title = title || fnName(fn) || '[anonymous]'; this.fn = isGeneratorFn(fn) ? co.wrap(fn) : fn; - this.assertCount = 0; + this.assertPromises = []; this.planCount = null; this.duration = null; this.assertError = undefined; + Object.defineProperty(this, 'assertCount', { + enumerable: true, + get: function () { + return this.assertPromises.length; + } + }); + // TODO(jamestalmage): make this an optional constructor arg instead of having Runner set it after the fact. // metadata should just always exist, otherwise it requires a bunch of ugly checks all over the place. this.metadata = {}; @@ -46,8 +53,8 @@ function Test(title, fn) { module.exports = Test; -Test.prototype._assert = function () { - this.assertCount++; +Test.prototype._assert = function (promise) { + this.assertPromises.push(promise); }; Test.prototype._setAssertError = function (err) { @@ -165,35 +172,41 @@ Test.prototype._end = function (err) { Test.prototype.exit = function () { var self = this; - // calculate total time spent in test - this.duration = globals.now() - this._timeStart; + Promise.all(this.assertPromises) + .catch(function (err) { + self._setAssertError(err); + }) + .finally(function () { + // calculate total time spent in test + self.duration = globals.now() - self._timeStart; - // stop infinite timer - globals.clearTimeout(this._timeout); + // stop infinite timer + globals.clearTimeout(self._timeout); - if (this.assertError === undefined && this.planCount !== null && this.planCount !== this.assertCount) { - this._setAssertError(new assert.AssertionError({ - actual: this.assertCount, - expected: this.planCount, - message: 'Assertion count does not match planned', - operator: 'plan' - })); + if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) { + self._setAssertError(new assert.AssertionError({ + actual: self.assertPromises.length, + expected: self.planCount, + message: 'Assertion count does not match planned', + operator: 'plan' + })); - this.assertError.stack = this.planStack; - } + self.assertError.stack = self.planStack; + } - if (!this.ended) { - this.ended = true; + if (!self.ended) { + self.ended = true; - globals.setImmediate(function () { - if (self.assertError !== undefined) { - self.promise.reject(self.assertError); - return; - } + globals.setImmediate(function () { + if (self.assertError !== undefined) { + self.promise.reject(self.assertError); + return; + } - self.promise.resolve(self); + self.promise.resolve(self); + }); + } }); - } }; Test.prototype._publicApi = function () { @@ -230,33 +243,23 @@ Test.prototype._publicApi = function () { api.plan = this.plan.bind(this); function skipFn() { - self._assert(); + self._assert(Promise.resolve()); } function onAssertionEvent(event) { + var promise; if (event.assertionThrew) { event.error.powerAssertContext = event.powerAssertContext; - event.error.originalMessage = event.originalMessage; - self._setAssertError(event.error); - self._assert(); - return null; + promise = Promise.reject(event.error); + } else { + promise = Promise.resolve(observableToPromise(event.returnValue)); } - - var fn = observableToPromise(event.returnValue); - - if (isPromise(fn)) { - return Promise.resolve(fn) - .catch(function (err) { - err.originalMessage = event.originalMessage; - self._setAssertError(err); - }) - .finally(function () { - self._assert(); - }); - } - - self._assert(); - return null; + promise = promise + .catch(function (err) { + err.originalMessage = event.originalMessage; + return Promise.reject(err); + }); + self._assert(promise); } var enhanced = enhanceAssert({ From 23c619c8e92d33480eca6dee2175cd5dbdf7b013 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 12:53:24 -0800 Subject: [PATCH 03/10] Add some tests regarding async assertions and t.end --- test/test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test.js b/test/test.js index 7ea62bc96..4ffcb0f29 100644 --- a/test/test.js +++ b/test/test.js @@ -376,3 +376,29 @@ test('throws and doesNotThrow work with promises', function (t) { t.end(); }); }); + +test('t.end is called when a promise passed to t.throws hasn\'t resolved yet', function (t) { + ava.cb(function (a) { + a.plan(1); + a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + a.end(); + }).run().then(function (a) { + t.ifError(a.assertError); + t.is(a.planCount, 1); + t.is(a.assertCount, 1); + t.end(); + }); +}); + +test('t.end is called when a promise passed to t.throws hasn\'t rejected yet', function (t) { + ava.cb(function (a) { + a.plan(1); + a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); + a.end(); + }).run().then(function (a) { + t.ifError(a.assertError); + t.is(a.planCount, 1); + t.is(a.assertCount, 1); + t.end(); + }); +}); From 796cb0b4b1d2d8af4bd244c54ebf9d24d107761c Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 12:58:07 -0800 Subject: [PATCH 04/10] Add some tests regarding async assertions and tests that return promises --- test/test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test.js b/test/test.js index 4ffcb0f29..492be3529 100644 --- a/test/test.js +++ b/test/test.js @@ -402,3 +402,29 @@ test('t.end is called when a promise passed to t.throws hasn\'t rejected yet', f t.end(); }); }); + +test('test returns a promise that resolves before a promise passed to t.throws resolves', function (t) { + ava(function (a) { + a.plan(1); + a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + return Promise.resolve(); + }).run().then(function (a) { + t.ifError(a.assertError); + t.is(a.planCount, 1); + t.is(a.assertCount, 1); + t.end(); + }); +}); + +test('test returns a promise that resolves before a promise passed to t.throws rejects', function (t) { + ava(function (a) { + a.plan(1); + a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); + return Promise.resolve(); + }).run().then(function (a) { + t.ifError(a.assertError); + t.is(a.planCount, 1); + t.is(a.assertCount, 1); + t.end(); + }); +}); From 913b78b7c3a5e8f69c3a4241e9221344f58b24eb Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 13:10:42 -0800 Subject: [PATCH 05/10] Add some tests regarding async assertions and t.plan --- test/test.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/test.js b/test/test.js index 492be3529..e665cc227 100644 --- a/test/test.js +++ b/test/test.js @@ -428,3 +428,34 @@ test('test returns a promise that resolves before a promise passed to t.throws r t.end(); }); }); + +test('multiple resolving and rejecting promises passed to t.throws/t.doesNotThrow', function (t) { + ava(function (a) { + a.plan(6); + for (var i = 0; i < 3; ++i) { + a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); + a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + } + }).run().then(function (a) { + t.ifError(a.assertError); + t.is(a.planCount, 6); + t.is(a.assertCount, 6); + t.end(); + }); +}); + +test('number of assertions matches t.plan when the test exits, but before all promises resolve another is added', function (t) { + ava(function (a) { + a.plan(2); + a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); + a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + setTimeout(function () { + a.throws(Promise.reject(new Error('foo')), 'foo'); + }, 5); + }).run().catch(function(err) { + t.is(err.operator, 'plan'); + t.is(err.actual, 3); + t.is(err.expected, 2); + t.end(); + }) +}); From 7a11cb1aa3b361bc07c63aae1550b838dc40ed49 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 13:21:10 -0800 Subject: [PATCH 06/10] Add some more tests regarding async assertions and t.plan --- test/test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test.js b/test/test.js index e665cc227..916c54137 100644 --- a/test/test.js +++ b/test/test.js @@ -459,3 +459,19 @@ test('number of assertions matches t.plan when the test exits, but before all pr t.end(); }) }); + +test('number of assertions doesn\'t t.plan when the test exits, but before all promises resolve another is added', function (t) { + ava(function (a) { + a.plan(3); + a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); + a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + setTimeout(function () { + a.throws(Promise.reject(new Error('foo')), 'foo'); + }, 5); + }).run().catch(function(err) { + t.is(err.operator, 'plan'); + t.is(err.actual, 2); + t.is(err.expected, 3); + t.end(); + }); +}); From a8d622bdbb2cd7eba0c8d7aa0aa6f50c3076f005 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 13:21:48 -0800 Subject: [PATCH 07/10] Fix t.plan when the number of assertions is incorrect when the test exits, but is correct once all assertions have resolved --- lib/test.js | 28 ++++++++++++++++++---------- test/test.js | 6 +++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/test.js b/lib/test.js index 78ca61c7a..37582d5e0 100644 --- a/lib/test.js +++ b/lib/test.js @@ -172,6 +172,23 @@ Test.prototype._end = function (err) { Test.prototype.exit = function () { var self = this; + function checkAssertLength() { + if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) { + self._setAssertError(new assert.AssertionError({ + actual: self.assertPromises.length, + expected: self.planCount, + message: 'Assertion count does not match planned', + operator: 'plan' + })); + + self.assertError.stack = self.planStack; + return false; + } + return true; + } + + checkAssertLength(); + Promise.all(this.assertPromises) .catch(function (err) { self._setAssertError(err); @@ -183,16 +200,7 @@ Test.prototype.exit = function () { // stop infinite timer globals.clearTimeout(self._timeout); - if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) { - self._setAssertError(new assert.AssertionError({ - actual: self.assertPromises.length, - expected: self.planCount, - message: 'Assertion count does not match planned', - operator: 'plan' - })); - - self.assertError.stack = self.planStack; - } + checkAssertLength(); if (!self.ended) { self.ended = true; diff --git a/test/test.js b/test/test.js index 916c54137..bd5a22df7 100644 --- a/test/test.js +++ b/test/test.js @@ -452,12 +452,12 @@ test('number of assertions matches t.plan when the test exits, but before all pr setTimeout(function () { a.throws(Promise.reject(new Error('foo')), 'foo'); }, 5); - }).run().catch(function(err) { + }).run().catch(function (err) { t.is(err.operator, 'plan'); t.is(err.actual, 3); t.is(err.expected, 2); t.end(); - }) + }); }); test('number of assertions doesn\'t t.plan when the test exits, but before all promises resolve another is added', function (t) { @@ -468,7 +468,7 @@ test('number of assertions doesn\'t t.plan when the test exits, but before all p setTimeout(function () { a.throws(Promise.reject(new Error('foo')), 'foo'); }, 5); - }).run().catch(function(err) { + }).run().catch(function (err) { t.is(err.operator, 'plan'); t.is(err.actual, 2); t.is(err.expected, 3); From 5461a649faa70b976c9c2d346baf387092ad446c Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 16:50:51 -0800 Subject: [PATCH 08/10] Clean up some things --- lib/test.js | 14 ++++++-------- package.json | 1 + test/test.js | 47 ++++++++++++++++++++++++----------------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/test.js b/lib/test.js index 37582d5e0..7ee13690e 100644 --- a/lib/test.js +++ b/lib/test.js @@ -25,7 +25,7 @@ function Test(title, fn) { this.title = title || fnName(fn) || '[anonymous]'; this.fn = isGeneratorFn(fn) ? co.wrap(fn) : fn; - this.assertPromises = []; + this.assertions = []; this.planCount = null; this.duration = null; this.assertError = undefined; @@ -33,7 +33,7 @@ function Test(title, fn) { Object.defineProperty(this, 'assertCount', { enumerable: true, get: function () { - return this.assertPromises.length; + return this.assertions.length; } }); @@ -54,7 +54,7 @@ function Test(title, fn) { module.exports = Test; Test.prototype._assert = function (promise) { - this.assertPromises.push(promise); + this.assertions.push(promise); }; Test.prototype._setAssertError = function (err) { @@ -173,23 +173,21 @@ Test.prototype.exit = function () { var self = this; function checkAssertLength() { - if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) { + if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertions.length) { self._setAssertError(new assert.AssertionError({ - actual: self.assertPromises.length, + actual: self.assertions.length, expected: self.planCount, message: 'Assertion count does not match planned', operator: 'plan' })); self.assertError.stack = self.planStack; - return false; } - return true; } checkAssertLength(); - Promise.all(this.assertPromises) + Promise.all(this.assertions) .catch(function (err) { self._setAssertError(err); }) diff --git a/package.json b/package.json index 63e405971..41166a22f 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "sinon": "^1.17.2", "source-map-fixtures": "^0.4.0", "tap": "^2.2.1", + "delay": "^1.2.0", "xo": "*", "zen-observable": "^0.1.6" }, diff --git a/test/test.js b/test/test.js index bd5a22df7..47d97ea59 100644 --- a/test/test.js +++ b/test/test.js @@ -1,12 +1,13 @@ 'use strict'; var test = require('tap').test; +var Promise = global.Promise = require('bluebird'); +var delay = require('delay'); var _ava = require('../lib/test'); -function delay(val, time) { - return new Promise(function (resolve) { - setTimeout(function () { - resolve(val); - }, time); +// This is a helper some boilerplate for testing `t.throws` +function delayReject(ms, message) { + return delay(ms).then(function () { + throw new Error(message); }); } @@ -364,10 +365,10 @@ test('throws and doesNotThrow work with promises', function (t) { var asyncCalled = false; ava(function (a) { a.plan(2); - a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); - a.doesNotThrow(delay(Promise.resolve().then(function () { + a.throws(delayReject(10, 'foo'), 'foo'); + a.doesNotThrow(delay(20).then(function () { asyncCalled = true; - }), 20)); + })); }).run().then(function (a) { t.ifError(a.assertError); t.is(a.planCount, 2); @@ -377,10 +378,10 @@ test('throws and doesNotThrow work with promises', function (t) { }); }); -test('t.end is called when a promise passed to t.throws hasn\'t resolved yet', function (t) { +test('waits for t.throws to resolve after t.end is called', function (t) { ava.cb(function (a) { a.plan(1); - a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + a.doesNotThrow(delay(10), 'foo'); a.end(); }).run().then(function (a) { 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 }); }); -test('t.end is called when a promise passed to t.throws hasn\'t rejected yet', function (t) { +test('waits for t.throws to reject after t.end is called', function (t) { ava.cb(function (a) { a.plan(1); - a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); + a.throws(delayReject(10, 'foo'), 'foo'); a.end(); }).run().then(function (a) { 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 }); }); -test('test returns a promise that resolves before a promise passed to t.throws resolves', function (t) { +test('waits for t.throws to resolve after the promise returned from the test resolves', function (t) { ava(function (a) { a.plan(1); - a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + a.doesNotThrow(delay(10), 'foo'); return Promise.resolve(); }).run().then(function (a) { t.ifError(a.assertError); @@ -416,10 +417,10 @@ test('test returns a promise that resolves before a promise passed to t.throws r }); }); -test('test returns a promise that resolves before a promise passed to t.throws rejects', function (t) { +test('waits for t.throws to reject after the promise returned from the test resolves', function (t) { ava(function (a) { a.plan(1); - a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); + a.throws(delayReject(10, 'foo'), 'foo'); return Promise.resolve(); }).run().then(function (a) { t.ifError(a.assertError); @@ -433,8 +434,8 @@ test('multiple resolving and rejecting promises passed to t.throws/t.doesNotThro ava(function (a) { a.plan(6); for (var i = 0; i < 3; ++i) { - a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); - a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + a.throws(delayReject(10, 'foo'), 'foo'); + a.doesNotThrow(delay(10), 'foo'); } }).run().then(function (a) { t.ifError(a.assertError); @@ -447,8 +448,8 @@ test('multiple resolving and rejecting promises passed to t.throws/t.doesNotThro test('number of assertions matches t.plan when the test exits, but before all promises resolve another is added', function (t) { ava(function (a) { a.plan(2); - a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); - a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + a.throws(delayReject(10, 'foo'), 'foo'); + a.doesNotThrow(delay(10), 'foo'); setTimeout(function () { a.throws(Promise.reject(new Error('foo')), 'foo'); }, 5); @@ -460,11 +461,11 @@ test('number of assertions matches t.plan when the test exits, but before all pr }); }); -test('number of assertions doesn\'t t.plan when the test exits, but before all promises resolve another is added', function (t) { +test('number of assertions doesn\'t match plan when the test exits, but before all promises resolve another is added', function (t) { ava(function (a) { a.plan(3); - a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo'); - a.doesNotThrow(delay(Promise.resolve(), 10), 'foo'); + a.throws(delayReject(10, 'foo'), 'foo'); + a.doesNotThrow(delay(10), 'foo'); setTimeout(function () { a.throws(Promise.reject(new Error('foo')), 'foo'); }, 5); From 716b37d92cd2fca43fee4ab49f5070defe5b2e44 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 23 Dec 2015 17:28:31 -0800 Subject: [PATCH 09/10] add Test.prototype._checkPlanCount() --- lib/test.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/test.js b/lib/test.js index 7ee13690e..1bffacf94 100644 --- a/lib/test.js +++ b/lib/test.js @@ -169,23 +169,23 @@ Test.prototype._end = function (err) { this.exit(); }; -Test.prototype.exit = function () { - var self = this; - - function checkAssertLength() { - if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertions.length) { - self._setAssertError(new assert.AssertionError({ - actual: self.assertions.length, - expected: self.planCount, - message: 'Assertion count does not match planned', - operator: 'plan' - })); +Test.prototype._checkPlanCount = function () { + if (this.assertError === undefined && this.planCount !== null && this.planCount !== this.assertions.length) { + this._setAssertError(new assert.AssertionError({ + actual: this.assertions.length, + expected: this.planCount, + message: 'Assertion count does not match planned', + operator: 'plan' + })); - self.assertError.stack = self.planStack; - } + this.assertError.stack = this.planStack; } +}; + +Test.prototype.exit = function () { + var self = this; - checkAssertLength(); + this._checkPlanCount(); Promise.all(this.assertions) .catch(function (err) { @@ -198,7 +198,7 @@ Test.prototype.exit = function () { // stop infinite timer globals.clearTimeout(self._timeout); - checkAssertLength(); + self._checkPlanCount(); if (!self.ended) { self.ended = true; From 0063076fe9a2176c7fa35b37bfbbf8d9853e470b Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Fri, 25 Dec 2015 14:18:47 -0800 Subject: [PATCH 10/10] Use delay.reject --- package.json | 2 +- test/test.js | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 41166a22f..9a558d617 100644 --- a/package.json +++ b/package.json @@ -120,11 +120,11 @@ }, "devDependencies": { "coveralls": "^2.11.4", + "delay": "^1.3.0", "signal-exit": "^2.1.2", "sinon": "^1.17.2", "source-map-fixtures": "^0.4.0", "tap": "^2.2.1", - "delay": "^1.2.0", "xo": "*", "zen-observable": "^0.1.6" }, diff --git a/test/test.js b/test/test.js index 47d97ea59..fb0ca9d1f 100644 --- a/test/test.js +++ b/test/test.js @@ -4,13 +4,6 @@ var Promise = global.Promise = require('bluebird'); var delay = require('delay'); var _ava = require('../lib/test'); -// This is a helper some boilerplate for testing `t.throws` -function delayReject(ms, message) { - return delay(ms).then(function () { - throw new Error(message); - }); -} - function ava() { var t = _ava.apply(null, arguments); t.metadata = {callback: false}; @@ -365,7 +358,7 @@ test('throws and doesNotThrow work with promises', function (t) { var asyncCalled = false; ava(function (a) { a.plan(2); - a.throws(delayReject(10, 'foo'), 'foo'); + a.throws(delay.reject(10, new Error('foo')), 'foo'); a.doesNotThrow(delay(20).then(function () { asyncCalled = true; })); @@ -394,7 +387,7 @@ test('waits for t.throws to resolve after t.end is called', function (t) { test('waits for t.throws to reject after t.end is called', function (t) { ava.cb(function (a) { a.plan(1); - a.throws(delayReject(10, 'foo'), 'foo'); + a.throws(delay.reject(10, new Error('foo')), 'foo'); a.end(); }).run().then(function (a) { t.ifError(a.assertError); @@ -420,7 +413,7 @@ test('waits for t.throws to resolve after the promise returned from the test res test('waits for t.throws to reject after the promise returned from the test resolves', function (t) { ava(function (a) { a.plan(1); - a.throws(delayReject(10, 'foo'), 'foo'); + a.throws(delay.reject(10, new Error('foo')), 'foo'); return Promise.resolve(); }).run().then(function (a) { t.ifError(a.assertError); @@ -434,7 +427,7 @@ test('multiple resolving and rejecting promises passed to t.throws/t.doesNotThro ava(function (a) { a.plan(6); for (var i = 0; i < 3; ++i) { - a.throws(delayReject(10, 'foo'), 'foo'); + a.throws(delay.reject(10, new Error('foo')), 'foo'); a.doesNotThrow(delay(10), 'foo'); } }).run().then(function (a) { @@ -448,7 +441,7 @@ test('multiple resolving and rejecting promises passed to t.throws/t.doesNotThro test('number of assertions matches t.plan when the test exits, but before all promises resolve another is added', function (t) { ava(function (a) { a.plan(2); - a.throws(delayReject(10, 'foo'), 'foo'); + a.throws(delay.reject(10, new Error('foo')), 'foo'); a.doesNotThrow(delay(10), 'foo'); setTimeout(function () { a.throws(Promise.reject(new Error('foo')), 'foo'); @@ -464,7 +457,7 @@ test('number of assertions matches t.plan when the test exits, but before all pr test('number of assertions doesn\'t match plan when the test exits, but before all promises resolve another is added', function (t) { ava(function (a) { a.plan(3); - a.throws(delayReject(10, 'foo'), 'foo'); + a.throws(delay.reject(10, new Error('foo')), 'foo'); a.doesNotThrow(delay(10), 'foo'); setTimeout(function () { a.throws(Promise.reject(new Error('foo')), 'foo');