Skip to content

Commit 30d51c3

Browse files
committed
mapAsyncIterable: use expectPromise in tests
1 parent 4822cb4 commit 30d51c3

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

src/execution/__tests__/mapAsyncIterable-test.ts

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33

4+
import { expectPromise } from '../../__testUtils__/expectPromise';
5+
46
import { mapAsyncIterable } from '../mapAsyncIterable';
57

68
/* eslint-disable @typescript-eslint/require-await */
@@ -209,14 +211,9 @@ describe('mapAsyncIterable', () => {
209211
expect(await doubles.next()).to.deep.equal({ value: 4, done: false });
210212

211213
// Throw error
212-
let caughtError;
213-
try {
214-
/* c8 ignore next 2 */
215-
await doubles.throw('ouch');
216-
} catch (e) {
217-
caughtError = e;
218-
}
219-
expect(caughtError).to.equal('ouch');
214+
const message = 'allows throwing errors when mapping async iterable';
215+
const thrown = doubles.throw(new Error(message));
216+
await expectPromise(thrown).toRejectWith(message);
220217
});
221218

222219
it('passes through caught errors through async generators', async () => {
@@ -265,17 +262,7 @@ describe('mapAsyncIterable', () => {
265262
done: false,
266263
});
267264

268-
let caughtError;
269-
try {
270-
/* c8 ignore next 2 */
271-
await doubles.next();
272-
} catch (e) {
273-
caughtError = e;
274-
}
275-
276-
expect(caughtError)
277-
.to.be.an.instanceOf(Error)
278-
.with.property('message', 'Goodbye');
265+
await expectPromise(doubles.next()).toRejectWith('Goodbye');
279266
});
280267

281268
async function testClosesSourceWithMapper<T>(mapper: (value: number) => T) {
@@ -297,17 +284,7 @@ describe('mapAsyncIterable', () => {
297284

298285
expect(await throwOver1.next()).to.deep.equal({ value: 1, done: false });
299286

300-
let expectedError;
301-
try {
302-
/* c8 ignore next 2 */
303-
await throwOver1.next();
304-
} catch (error) {
305-
expectedError = error;
306-
}
307-
308-
expect(expectedError)
309-
.to.be.an.instanceOf(Error)
310-
.with.property('message', 'Cannot count to 2');
287+
await expectPromise(throwOver1.next()).toRejectWith('Cannot count to 2');
311288

312289
expect(await throwOver1.next()).to.deep.equal({
313290
value: undefined,

0 commit comments

Comments
 (0)