Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: usingMatchers mention toStrictEqual
  • Loading branch information
necipallef authored Nov 4, 2022
commit fe0118fe9ecfbc6b4a0c76b3e7679f7198fa67aa
10 changes: 8 additions & 2 deletions docs/UsingMatchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('two plus two is four', () => {

In this code, `expect(2 + 2)` returns an "expectation" object. You typically won't do much with these expectation objects except call matchers on them. In this code, `.toBe(4)` is the matcher. When Jest runs, it tracks all the failing matchers so that it can print out nice error messages for you.

`toBe` uses `Object.is` to test exact equality. If you want to check the value of an object, use `toEqual` instead:
`toBe` uses `Object.is` to test exact equality. If you want to check the value of an object, use `toEqual` or `toStrictEqual` instead:

```js
test('object assignment', () => {
Expand All @@ -29,7 +29,13 @@ test('object assignment', () => {

`toEqual` recursively checks every field of an object or array.

You can also test for the opposite of a matcher:
:::tip

Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.

:::

You can also test for the opposite of a matcher using `not`:

```js
test('adding positive numbers is not zero', () => {
Expand Down