diff --git a/types/code/code-tests.ts b/types/code/code-tests.ts index 1c2fa78fe5..9e5f12645f 100644 --- a/types/code/code-tests.ts +++ b/types/code/code-tests.ts @@ -159,3 +159,11 @@ expect(foo).to.equal([]); const bar = Object.create(null); settings.comparePrototypes = false; expect(bar).to.equal({}); + +const rejection = Promise.reject(new Error('Oh no!')); +/* await */ expect(rejection).to.reject('Oh no!'); +/* await */ expect(rejection).rejects('Oh no!'); + +const typedRejection = Promise.reject(new CustomError('Oh no!')); +/* await */ expect(typedRejection).to.reject(CustomError, 'Oh no!'); +/* await */ expect(typedRejection).rejects(CustomError, 'Oh no!'); diff --git a/types/code/index.d.ts b/types/code/index.d.ts index 7541831db2..3bdca4be9a 100644 --- a/types/code/index.d.ts +++ b/types/code/index.d.ts @@ -160,6 +160,10 @@ export interface Values { match(regex: RegExp): AssertionChain; /** Asserts that the reference value's toString() representation matches the provided regular expression. */ matches(regex: RegExp): AssertionChain; + /** Asserts that the Promise reference value rejects with an exception when called */ + reject(type?: any, message?: string | RegExp): AssertionChain; + /** Asserts that the Promise reference value rejects with an exception when called */ + rejects(type?: any, message?: string | RegExp): AssertionChain; /** Asserts that the reference value satisfies the provided validator function. */ satisfy(validator: (value: T) => boolean): AssertionChain; /** Asserts that the reference value satisfies the provided validator function. */