Skip to content

Commit 491827b

Browse files
authored
docs: usingMatchers mention toStrictEqual (#13560)
1 parent f75a3aa commit 491827b

File tree

9 files changed

+65
-16
lines changed

9 files changed

+65
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### Chore & Maintenance
1414

1515
- `[@jest/transform]` Update `convert-source-map` ([#13509](https://github.com/facebook/jest/pull/13509))
16+
- `[docs]` Mention `toStrictEqual` in UsingMatchers docs. ([#13560](https://github.com/facebook/jest/pull/13560))
1617

1718
### Performance
1819

docs/UsingMatchers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('two plus two is four', () => {
1717

1818
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.
1919

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

2222
```js
2323
test('object assignment', () => {
@@ -29,7 +29,13 @@ test('object assignment', () => {
2929

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

32-
You can also test for the opposite of a matcher:
32+
:::tip
33+
34+
Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.
35+
36+
:::
37+
38+
You can also test for the opposite of a matcher using `not`:
3339

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

website/versioned_docs/version-25.x/UsingMatchers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('two plus two is four', () => {
1717

1818
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.
1919

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

2222
```js
2323
test('object assignment', () => {
@@ -29,7 +29,13 @@ test('object assignment', () => {
2929

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

32-
You can also test for the opposite of a matcher:
32+
:::tip
33+
34+
Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.
35+
36+
:::
37+
38+
You can also test for the opposite of a matcher using `not`:
3339

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

website/versioned_docs/version-26.x/UsingMatchers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('two plus two is four', () => {
1717

1818
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.
1919

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

2222
```js
2323
test('object assignment', () => {
@@ -29,7 +29,13 @@ test('object assignment', () => {
2929

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

32-
You can also test for the opposite of a matcher:
32+
:::tip
33+
34+
Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.
35+
36+
:::
37+
38+
You can also test for the opposite of a matcher using `not`:
3339

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

website/versioned_docs/version-27.x/UsingMatchers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('two plus two is four', () => {
1717

1818
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.
1919

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

2222
```js
2323
test('object assignment', () => {
@@ -29,7 +29,13 @@ test('object assignment', () => {
2929

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

32-
You can also test for the opposite of a matcher:
32+
:::tip
33+
34+
Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.
35+
36+
:::
37+
38+
You can also test for the opposite of a matcher using `not`:
3339

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

website/versioned_docs/version-28.x/UsingMatchers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('two plus two is four', () => {
1717

1818
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.
1919

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

2222
```js
2323
test('object assignment', () => {
@@ -29,7 +29,13 @@ test('object assignment', () => {
2929

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

32-
You can also test for the opposite of a matcher:
32+
:::tip
33+
34+
Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.
35+
36+
:::
37+
38+
You can also test for the opposite of a matcher using `not`:
3339

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

website/versioned_docs/version-29.0/UsingMatchers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('two plus two is four', () => {
1717

1818
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.
1919

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

2222
```js
2323
test('object assignment', () => {
@@ -29,7 +29,13 @@ test('object assignment', () => {
2929

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

32-
You can also test for the opposite of a matcher:
32+
:::tip
33+
34+
Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.
35+
36+
:::
37+
38+
You can also test for the opposite of a matcher using `not`:
3339

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

website/versioned_docs/version-29.1/UsingMatchers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('two plus two is four', () => {
1717

1818
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.
1919

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

2222
```js
2323
test('object assignment', () => {
@@ -29,7 +29,13 @@ test('object assignment', () => {
2929

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

32-
You can also test for the opposite of a matcher:
32+
:::tip
33+
34+
Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.
35+
36+
:::
37+
38+
You can also test for the opposite of a matcher using `not`:
3339

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

website/versioned_docs/version-29.2/UsingMatchers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('two plus two is four', () => {
1717

1818
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.
1919

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

2222
```js
2323
test('object assignment', () => {
@@ -29,7 +29,13 @@ test('object assignment', () => {
2929

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

32-
You can also test for the opposite of a matcher:
32+
:::tip
33+
34+
Using `toStrictEqual` is preferred over using `toEqual`. `toEqual` simply ignores `undefined` values, whereas `toStrictEqual` takes them into account.
35+
36+
:::
37+
38+
You can also test for the opposite of a matcher using `not`:
3339

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

0 commit comments

Comments
 (0)