diff --git a/docs/ExpectAPI.md b/docs/ExpectAPI.md index da7a47365058..aa25136d861b 100644 --- a/docs/ExpectAPI.md +++ b/docs/ExpectAPI.md @@ -67,7 +67,9 @@ test('numeric ranges', () => { }); ``` -_Note_: In TypeScript, when using `@types/jest` for example, you can declare the new `toBeWithinRange` matcher in the imported module like this: +:::note + +In TypeScript, when using `@types/jest` for example, you can declare the new `toBeWithinRange` matcher in the imported module like this: ```ts interface CustomMatchers { @@ -83,6 +85,8 @@ declare global { } ``` +::: + #### Async Matchers `expect.extend` also supports async matchers. Async matchers return a Promise so you will need to await the returned value. Let's use an example matcher to illustrate the usage of them. We are going to implement a matcher called `toBeDivisibleByExternalValue`, where the divisible number is going to be pulled from an external source. @@ -800,7 +804,11 @@ test('drinkEach drinks each drink', () => { }); ``` -Note: the nth argument must be positive integer starting from 1. +:::note + +The nth argument must be positive integer starting from 1. + +::: ### `.toHaveReturned()` @@ -899,7 +907,11 @@ test('drink returns expected nth calls', () => { }); ``` -Note: the nth argument must be positive integer starting from 1. +:::note + +The nth argument must be positive integer starting from 1. + +::: ### `.toHaveLength(number)` @@ -1205,7 +1217,11 @@ describe('the La Croix cans on my desk', () => { }); ``` -> Note: `.toEqual` won't perform a _deep equality_ check for two errors. Only the `message` property of an Error is considered for equality. It is recommended to use the `.toThrow` matcher for testing against errors. +:::tip + +`.toEqual` won't perform a _deep equality_ check for two errors. Only the `message` property of an Error is considered for equality. It is recommended to use the `.toThrow` matcher for testing against errors. + +::: If differences between properties do not help you to understand why a test fails, especially if the report is large, then you might move the comparison into the `expect` function. For example, use `equals` method of `Buffer` class to assert whether or not buffers contain the same content: @@ -1340,7 +1356,11 @@ test('throws on octopus', () => { }); ``` -> Note: You must wrap the code in a function, otherwise the error will not be caught and the assertion will fail. +:::tip + +You must wrap the code in a function, otherwise the error will not be caught and the assertion will fail. + +::: You can provide an optional argument to test that a specific error is thrown: