docs: add GenericAssertions.toBeOneOf

This commit is contained in:
Pengoose 2024-12-04 02:40:35 +09:00
parent 2c49231568
commit ba140b1b83
4 changed files with 48 additions and 0 deletions

View file

@ -227,6 +227,30 @@ expect(value).toBeNull();
``` ```
## method: GenericAssertions.toBeOneOf
* since: v1.49.1
Ensures that value is deeply equal to one of the elements in the expected array.
**Usage**
```js
const value = 2;
expect(value).toBeOneOf([1, 2, 3]);
expect(value).not.toBeOneOf([4, 5, 6]);
const obj = { a: 1 };
expect(obj).toBeOneOf([{ a: 1 }, { b: 2 }]);
expect(obj).not.toBeOneOf([{ a: 2 }, { b: 3 }]);
```
### param: GenericAssertions.toBeOneOf.expected
* since: v1.49.1
- `expected` <[Array]<[any]>>
Expected array to match against.
## method: GenericAssertions.toBeTruthy ## method: GenericAssertions.toBeTruthy
* since: v1.9 * since: v1.9

View file

@ -222,6 +222,11 @@ export interface Matchers<R extends void | Promise<void>, T = unknown> {
* So use `.toBeNull()` when you want to check that something is null. * So use `.toBeNull()` when you want to check that something is null.
*/ */
toBeNull(): R; toBeNull(): R;
/**
* Use when you don't care what a value is, you just want to ensure a value
* is not null. You will often see it in tests for checking that a callback
*/
toBeOneOf(expected: Array<unknown>): R;
/** /**
* Use when you don't care what a value is, you just want to ensure a value * Use when you don't care what a value is, you just want to ensure a value
* is true in a boolean context. In JavaScript, there are six falsy values: * is true in a boolean context. In JavaScript, there are six falsy values:

View file

@ -7040,6 +7040,24 @@ interface GenericAssertions<R> {
* *
*/ */
toBeNull(): R; toBeNull(): R;
/**
* Ensures that value is deeply equal to one of the elements in the expected array.
*
* **Usage**
*
* ```js
* const value = 2;
* expect(value).toBeOneOf([1, 2, 3]);
* expect(value).not.toBeOneOf([4, 5, 6]);
*
* const obj = { a: 1 };
* expect(obj).toBeOneOf([{ a: 1 }, { b: 2 }]);
* expect(obj).not.toBeOneOf([{ a: 2 }, { b: 3 }]);
* ```
*
* @param expected Expected array to match against.
*/
toBeOneOf(expected: unknown[]): R;
/** /**
* Ensures that value is true in a boolean context, **anything but** `false`, `0`, `''`, `null`, `undefined` or `NaN`. * Ensures that value is true in a boolean context, **anything but** `false`, `0`, `''`, `null`, `undefined` or `NaN`.
* Use this method when you don't care about the specific value. * Use this method when you don't care about the specific value.

View file

@ -314,6 +314,7 @@ interface GenericAssertions<R> {
toBeLessThanOrEqual(expected: number | bigint): R; toBeLessThanOrEqual(expected: number | bigint): R;
toBeNaN(): R; toBeNaN(): R;
toBeNull(): R; toBeNull(): R;
toBeOneOf(expected: unknown[]): R;
toBeTruthy(): R; toBeTruthy(): R;
toBeUndefined(): R; toBeUndefined(): R;
toContain(expected: string): R; toContain(expected: string): R;