0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

docs(testing): add assertObjectMatch example (#9645)

This commit is contained in:
Yasser A.Idrissi 2021-03-02 15:05:38 +01:00 committed by GitHub
parent faf2e80272
commit 07626645e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,7 @@ The assertions module provides 10 assertions:
- `assertArrayIncludes(actual: unknown[], expected: unknown[], msg?: string): void`
- `assertMatch(actual: string, expected: RegExp, msg?: string): void`
- `assertNotMatch(actual: string, expected: RegExp, msg?: string): void`
- `assertObjectMatch( actual: Record<PropertyKey, unknown>, expected: Record<PropertyKey, unknown>): void`
- `assertThrows(fn: () => void, ErrorClass?: Constructor, msgIncludes = "", msg?: string): Error`
- `assertThrowsAsync(fn: () => Promise<void>, ErrorClass?: Constructor, msgIncludes = "", msg?: string): Promise<Error>`
@ -136,6 +137,21 @@ Deno.test("Test Assert Not Match", () => {
});
```
### Object
Use `assertObjectMatch` to check that a JavaScript object matches a subset of
the properties of an object.
```js
// Simple subset
assertObjectMatch(
{ foo: true, bar: false },
{
foo: true,
},
);
```
### Throws
There are two ways to assert whether something throws an error in Deno,