Use assert.isRejected
instead of custom assertRejects
This commit is contained in:
parent
683823a114
commit
43f843f9fc
3 changed files with 7 additions and 26 deletions
|
@ -1,17 +0,0 @@
|
|||
// Copyright 2020 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
export async function assertRejects(fn: () => Promise<unknown>): Promise<void> {
|
||||
let err: unknown;
|
||||
try {
|
||||
await fn();
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
assert(
|
||||
err instanceof Error,
|
||||
'Expected promise to reject with an Error, but it resolved'
|
||||
);
|
||||
}
|
|
@ -13,7 +13,6 @@ import PQueue from 'p-queue';
|
|||
import { JobError } from '../../jobs/JobError';
|
||||
import { TestJobQueueStore } from './TestJobQueueStore';
|
||||
import { missingCaseError } from '../../util/missingCaseError';
|
||||
import { assertRejects } from '../helpers';
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
|
||||
import { JobQueue } from '../../jobs/JobQueue';
|
||||
|
@ -803,8 +802,8 @@ describe('JobQueue', () => {
|
|||
|
||||
noopQueue.streamJobs();
|
||||
|
||||
await assertRejects(() => noopQueue.streamJobs());
|
||||
await assertRejects(() => noopQueue.streamJobs());
|
||||
await assert.isRejected(noopQueue.streamJobs());
|
||||
await assert.isRejected(noopQueue.streamJobs());
|
||||
|
||||
sinon.assert.calledOnce(fakeStore.stream as sinon.SinonStub);
|
||||
});
|
||||
|
@ -834,7 +833,7 @@ describe('JobQueue', () => {
|
|||
maxAttempts: 99,
|
||||
});
|
||||
|
||||
await assertRejects(() => noopQueue.add(undefined));
|
||||
await assert.isRejected(noopQueue.add(undefined));
|
||||
|
||||
sinon.assert.notCalled(fakeStore.stream as sinon.SinonStub);
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020 Signal Messenger, LLC
|
||||
// Copyright 2020-2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
@ -7,7 +7,6 @@ import * as os from 'os';
|
|||
import * as fs from 'fs';
|
||||
import * as fse from 'fs-extra';
|
||||
import * as Sinon from 'sinon';
|
||||
import { assertRejects } from '../helpers';
|
||||
|
||||
import { writeWindowsZoneIdentifier } from '../../util/windowsZoneIdentifier';
|
||||
|
||||
|
@ -47,13 +46,13 @@ describe('writeWindowsZoneIdentifier', () => {
|
|||
await fse.outputFile(file, 'hello');
|
||||
await fs.promises.writeFile(`${file}:Zone.Identifier`, '# already here');
|
||||
|
||||
await assertRejects(() => writeWindowsZoneIdentifier(file));
|
||||
await assert.isRejected(writeWindowsZoneIdentifier(file));
|
||||
});
|
||||
|
||||
it('fails if the original file does not exist', async function thisNeeded() {
|
||||
const file = path.join(this.tmpdir, 'file-never-created.txt');
|
||||
|
||||
await assertRejects(() => writeWindowsZoneIdentifier(file));
|
||||
await assert.isRejected(writeWindowsZoneIdentifier(file));
|
||||
});
|
||||
|
||||
it('fails if not on Windows', async function thisNeeded() {
|
||||
|
@ -62,6 +61,6 @@ describe('writeWindowsZoneIdentifier', () => {
|
|||
const file = path.join(this.tmpdir, 'file.txt');
|
||||
await fse.outputFile(file, 'hello');
|
||||
|
||||
await assertRejects(() => writeWindowsZoneIdentifier(file));
|
||||
await assert.isRejected(writeWindowsZoneIdentifier(file));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue