/* eslint-disable @typescript-eslint/no-empty-function */ import {expectError, expectType} from 'tsd'; import test from '../../entrypoints/main.mjs'; class CustomError extends Error { foo: string; constructor() { super(); this.foo = 'foo'; } } test('throws', t => { const error1 = t.throws(() => {}); expectType(error1); const error2: CustomError = t.throws(() => {}); expectType(error2); expectType(t.throws(() => {})); const error3 = t.throws(() => {}, {instanceOf: CustomError}); expectType(error3); const error4 = t.throws(() => {}, {is: new CustomError()}); expectType(error4); const error5 = t.throws(() => {}, {instanceOf: CustomError, is: new CustomError()}); expectType(error5); const error6 = t.throws(() => { throw 'foo'; // eslint-disable-line @typescript-eslint/no-throw-literal }, {any: true}); expectType(error6); expectError(t.throws(() => { throw 'foo'; // eslint-disable-line @typescript-eslint/no-throw-literal // @ts-expect-error TS2769 }, {instanceOf: String, is: 'foo'})); }); test('throwsAsync', async t => { const error1 = await t.throwsAsync(async () => {}); expectType(error1); expectType(await t.throwsAsync(async () => {})); const error2 = await t.throwsAsync(Promise.reject()); expectType(error2); expectType(await t.throwsAsync(Promise.reject())); const error3 = await t.throwsAsync(async () => {}, {instanceOf: CustomError}); expectType(error3); const error4 = await t.throwsAsync(async () => {}, {is: new CustomError()}); expectType(error4); const error5 = await t.throwsAsync(async () => {}, {instanceOf: CustomError, is: new CustomError()}); expectType(error5); const error6 = await t.throwsAsync(async () => { throw 'foo'; // eslint-disable-line @typescript-eslint/no-throw-literal }, {any: true}); expectType(error6); // @ts-expect-error TS2769 expectError(t.throwsAsync(async () => { throw 'foo'; // eslint-disable-line @typescript-eslint/no-throw-literal }, {instanceOf: String, is: 'foo'})); });