Add typings for reject/rejects from code 5.0.0

Documentation:

> * [`await reject([type], [message])`][artm]
>
> Asserts that the `Promise` reference value rejects with an exception
> when called

[artm]: https://github.com/hapijs/code/blob/v5.0.0/API.md#await-rejecttype-message
This commit is contained in:
Garth Kidd
2018-02-08 22:43:16 +11:00
parent a593fd2d60
commit 3638491eae
2 changed files with 12 additions and 0 deletions

View File

@@ -159,3 +159,11 @@ expect<number[]>(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!');

View File

@@ -160,6 +160,10 @@ export interface Values<T> {
match(regex: RegExp): AssertionChain<T>;
/** Asserts that the reference value's toString() representation matches the provided regular expression. */
matches(regex: RegExp): AssertionChain<T>;
/** Asserts that the Promise reference value rejects with an exception when called */
reject(type?: any, message?: string | RegExp): AssertionChain<T>;
/** Asserts that the Promise reference value rejects with an exception when called */
rejects(type?: any, message?: string | RegExp): AssertionChain<T>;
/** Asserts that the reference value satisfies the provided validator function. */
satisfy(validator: (value: T) => boolean): AssertionChain<T>;
/** Asserts that the reference value satisfies the provided validator function. */