diff --git a/CHANGELOG.md b/CHANGELOG.md index ca3ed36a4d3b..134c024a0895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ - `[babel-jest, babel-preset-jest]` [**BREAKING**] Increase peer dependency of `@babel/core` to `^7.11` ([#14109](https://github.com/jestjs/jest/pull/14109)) - `[jest-cli, jest-config, @jest/types]` [**BREAKING**] Remove deprecated `--init` argument ([#14490](https://github.com/jestjs/jest/pull/14490)) - `[docs]` Fix typos in `CHANGELOG.md` and `packages/jest-validate/README.md` ([#14640](https://github.com/jestjs/jest/pull/14640)) +- `[docs]` Don't use alias matchers in docs ([#14631](https://github.com/facebook/jest/pull/14631)) ## 29.7.0 diff --git a/docs/ExpectAPI.md b/docs/ExpectAPI.md index 4ac41d8a094c..1d4574c63b01 100644 --- a/docs/ExpectAPI.md +++ b/docs/ExpectAPI.md @@ -888,7 +888,7 @@ Check out the section on [Inline Snapshots](SnapshotTesting.md#inline-snapshots) ### `expect.anything()` -`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: +`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: ```js test('map calls its argument with a non-null argument', () => { @@ -900,7 +900,7 @@ test('map calls its argument with a non-null argument', () => { ### `expect.any(constructor)` -`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: +`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: ```js class Cat {} @@ -931,7 +931,7 @@ test('randocall calls its callback with a number', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match a property in `objectContaining` or `toMatchObject` ```js @@ -1063,7 +1063,7 @@ describe('not.stringContaining', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match an element in `arrayContaining` - to match a property in `objectContaining` or `toMatchObject` diff --git a/docs/TimerMocks.md b/docs/TimerMocks.md index 4fe263131964..14f368abbb3e 100644 --- a/docs/TimerMocks.md +++ b/docs/TimerMocks.md @@ -53,13 +53,13 @@ test('calls the callback after 1 second', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.runAllTimers(); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` @@ -109,7 +109,7 @@ describe('infiniteTimerGame', () => { jest.runOnlyPendingTimers(); // At this point, our 1-second timer should have fired its callback - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); // And it should have created a new timer to start the game over in // 10 seconds @@ -154,13 +154,13 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.advanceTimersByTime(1000); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` @@ -181,12 +181,12 @@ it('calls the animation frame callback after advanceTimersToNextFrame()', () => requestAnimationFrame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); jest.advanceTimersToNextFrame(); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` diff --git a/docs/TutorialjQuery.md b/docs/TutorialjQuery.md index a1c542a4f12b..3a8e36b92b47 100644 --- a/docs/TutorialjQuery.md +++ b/docs/TutorialjQuery.md @@ -54,7 +54,7 @@ test('displays a user after a click', () => { // Assert that the fetchCurrentUser function was called, and that the // #username span's inner text was updated as we'd expect it to. - expect(fetchCurrentUser).toBeCalled(); + expect(fetchCurrentUser).toHaveBeenCalled(); expect($('#username').text()).toBe('Johnny Cash - Logged In'); }); ``` diff --git a/website/versioned_docs/version-29.4/ExpectAPI.md b/website/versioned_docs/version-29.4/ExpectAPI.md index 4ac41d8a094c..1d4574c63b01 100644 --- a/website/versioned_docs/version-29.4/ExpectAPI.md +++ b/website/versioned_docs/version-29.4/ExpectAPI.md @@ -888,7 +888,7 @@ Check out the section on [Inline Snapshots](SnapshotTesting.md#inline-snapshots) ### `expect.anything()` -`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: +`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: ```js test('map calls its argument with a non-null argument', () => { @@ -900,7 +900,7 @@ test('map calls its argument with a non-null argument', () => { ### `expect.any(constructor)` -`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: +`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: ```js class Cat {} @@ -931,7 +931,7 @@ test('randocall calls its callback with a number', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match a property in `objectContaining` or `toMatchObject` ```js @@ -1063,7 +1063,7 @@ describe('not.stringContaining', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match an element in `arrayContaining` - to match a property in `objectContaining` or `toMatchObject` diff --git a/website/versioned_docs/version-29.4/TimerMocks.md b/website/versioned_docs/version-29.4/TimerMocks.md index 1e0260c7def6..fb53640baccf 100644 --- a/website/versioned_docs/version-29.4/TimerMocks.md +++ b/website/versioned_docs/version-29.4/TimerMocks.md @@ -53,13 +53,13 @@ test('calls the callback after 1 second', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.runAllTimers(); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` @@ -109,7 +109,7 @@ describe('infiniteTimerGame', () => { jest.runOnlyPendingTimers(); // At this point, our 1-second timer should have fired its callback - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); // And it should have created a new timer to start the game over in // 10 seconds @@ -154,13 +154,13 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.advanceTimersByTime(1000); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` diff --git a/website/versioned_docs/version-29.4/TutorialjQuery.md b/website/versioned_docs/version-29.4/TutorialjQuery.md index a1c542a4f12b..3a8e36b92b47 100644 --- a/website/versioned_docs/version-29.4/TutorialjQuery.md +++ b/website/versioned_docs/version-29.4/TutorialjQuery.md @@ -54,7 +54,7 @@ test('displays a user after a click', () => { // Assert that the fetchCurrentUser function was called, and that the // #username span's inner text was updated as we'd expect it to. - expect(fetchCurrentUser).toBeCalled(); + expect(fetchCurrentUser).toHaveBeenCalled(); expect($('#username').text()).toBe('Johnny Cash - Logged In'); }); ``` diff --git a/website/versioned_docs/version-29.5/ExpectAPI.md b/website/versioned_docs/version-29.5/ExpectAPI.md index 4ac41d8a094c..1d4574c63b01 100644 --- a/website/versioned_docs/version-29.5/ExpectAPI.md +++ b/website/versioned_docs/version-29.5/ExpectAPI.md @@ -888,7 +888,7 @@ Check out the section on [Inline Snapshots](SnapshotTesting.md#inline-snapshots) ### `expect.anything()` -`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: +`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: ```js test('map calls its argument with a non-null argument', () => { @@ -900,7 +900,7 @@ test('map calls its argument with a non-null argument', () => { ### `expect.any(constructor)` -`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: +`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: ```js class Cat {} @@ -931,7 +931,7 @@ test('randocall calls its callback with a number', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match a property in `objectContaining` or `toMatchObject` ```js @@ -1063,7 +1063,7 @@ describe('not.stringContaining', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match an element in `arrayContaining` - to match a property in `objectContaining` or `toMatchObject` diff --git a/website/versioned_docs/version-29.5/TimerMocks.md b/website/versioned_docs/version-29.5/TimerMocks.md index 1e0260c7def6..fb53640baccf 100644 --- a/website/versioned_docs/version-29.5/TimerMocks.md +++ b/website/versioned_docs/version-29.5/TimerMocks.md @@ -53,13 +53,13 @@ test('calls the callback after 1 second', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.runAllTimers(); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` @@ -109,7 +109,7 @@ describe('infiniteTimerGame', () => { jest.runOnlyPendingTimers(); // At this point, our 1-second timer should have fired its callback - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); // And it should have created a new timer to start the game over in // 10 seconds @@ -154,13 +154,13 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.advanceTimersByTime(1000); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` diff --git a/website/versioned_docs/version-29.5/TutorialjQuery.md b/website/versioned_docs/version-29.5/TutorialjQuery.md index a1c542a4f12b..3a8e36b92b47 100644 --- a/website/versioned_docs/version-29.5/TutorialjQuery.md +++ b/website/versioned_docs/version-29.5/TutorialjQuery.md @@ -54,7 +54,7 @@ test('displays a user after a click', () => { // Assert that the fetchCurrentUser function was called, and that the // #username span's inner text was updated as we'd expect it to. - expect(fetchCurrentUser).toBeCalled(); + expect(fetchCurrentUser).toHaveBeenCalled(); expect($('#username').text()).toBe('Johnny Cash - Logged In'); }); ``` diff --git a/website/versioned_docs/version-29.6/ExpectAPI.md b/website/versioned_docs/version-29.6/ExpectAPI.md index 4ac41d8a094c..1d4574c63b01 100644 --- a/website/versioned_docs/version-29.6/ExpectAPI.md +++ b/website/versioned_docs/version-29.6/ExpectAPI.md @@ -888,7 +888,7 @@ Check out the section on [Inline Snapshots](SnapshotTesting.md#inline-snapshots) ### `expect.anything()` -`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: +`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: ```js test('map calls its argument with a non-null argument', () => { @@ -900,7 +900,7 @@ test('map calls its argument with a non-null argument', () => { ### `expect.any(constructor)` -`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: +`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: ```js class Cat {} @@ -931,7 +931,7 @@ test('randocall calls its callback with a number', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match a property in `objectContaining` or `toMatchObject` ```js @@ -1063,7 +1063,7 @@ describe('not.stringContaining', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match an element in `arrayContaining` - to match a property in `objectContaining` or `toMatchObject` diff --git a/website/versioned_docs/version-29.6/TimerMocks.md b/website/versioned_docs/version-29.6/TimerMocks.md index 1e0260c7def6..fb53640baccf 100644 --- a/website/versioned_docs/version-29.6/TimerMocks.md +++ b/website/versioned_docs/version-29.6/TimerMocks.md @@ -53,13 +53,13 @@ test('calls the callback after 1 second', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.runAllTimers(); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` @@ -109,7 +109,7 @@ describe('infiniteTimerGame', () => { jest.runOnlyPendingTimers(); // At this point, our 1-second timer should have fired its callback - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); // And it should have created a new timer to start the game over in // 10 seconds @@ -154,13 +154,13 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.advanceTimersByTime(1000); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` diff --git a/website/versioned_docs/version-29.6/TutorialjQuery.md b/website/versioned_docs/version-29.6/TutorialjQuery.md index a1c542a4f12b..3a8e36b92b47 100644 --- a/website/versioned_docs/version-29.6/TutorialjQuery.md +++ b/website/versioned_docs/version-29.6/TutorialjQuery.md @@ -54,7 +54,7 @@ test('displays a user after a click', () => { // Assert that the fetchCurrentUser function was called, and that the // #username span's inner text was updated as we'd expect it to. - expect(fetchCurrentUser).toBeCalled(); + expect(fetchCurrentUser).toHaveBeenCalled(); expect($('#username').text()).toBe('Johnny Cash - Logged In'); }); ``` diff --git a/website/versioned_docs/version-29.7/ExpectAPI.md b/website/versioned_docs/version-29.7/ExpectAPI.md index 4ac41d8a094c..1d4574c63b01 100644 --- a/website/versioned_docs/version-29.7/ExpectAPI.md +++ b/website/versioned_docs/version-29.7/ExpectAPI.md @@ -888,7 +888,7 @@ Check out the section on [Inline Snapshots](SnapshotTesting.md#inline-snapshots) ### `expect.anything()` -`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: +`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument: ```js test('map calls its argument with a non-null argument', () => { @@ -900,7 +900,7 @@ test('map calls its argument with a non-null argument', () => { ### `expect.any(constructor)` -`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: +`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number: ```js class Cat {} @@ -931,7 +931,7 @@ test('randocall calls its callback with a number', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match a property in `objectContaining` or `toMatchObject` ```js @@ -1063,7 +1063,7 @@ describe('not.stringContaining', () => { You can use it instead of a literal value: -- in `toEqual` or `toBeCalledWith` +- in `toEqual` or `toHaveBeenCalledWith` - to match an element in `arrayContaining` - to match a property in `objectContaining` or `toMatchObject` diff --git a/website/versioned_docs/version-29.7/TimerMocks.md b/website/versioned_docs/version-29.7/TimerMocks.md index 1e0260c7def6..fb53640baccf 100644 --- a/website/versioned_docs/version-29.7/TimerMocks.md +++ b/website/versioned_docs/version-29.7/TimerMocks.md @@ -53,13 +53,13 @@ test('calls the callback after 1 second', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.runAllTimers(); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` @@ -109,7 +109,7 @@ describe('infiniteTimerGame', () => { jest.runOnlyPendingTimers(); // At this point, our 1-second timer should have fired its callback - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); // And it should have created a new timer to start the game over in // 10 seconds @@ -154,13 +154,13 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { timerGame(callback); // At this point in time, the callback should not have been called yet - expect(callback).not.toBeCalled(); + expect(callback).not.toHaveBeenCalled(); // Fast-forward until all timers have been executed jest.advanceTimersByTime(1000); // Now our callback should have been called! - expect(callback).toBeCalled(); + expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalledTimes(1); }); ``` diff --git a/website/versioned_docs/version-29.7/TutorialjQuery.md b/website/versioned_docs/version-29.7/TutorialjQuery.md index a1c542a4f12b..3a8e36b92b47 100644 --- a/website/versioned_docs/version-29.7/TutorialjQuery.md +++ b/website/versioned_docs/version-29.7/TutorialjQuery.md @@ -54,7 +54,7 @@ test('displays a user after a click', () => { // Assert that the fetchCurrentUser function was called, and that the // #username span's inner text was updated as we'd expect it to. - expect(fetchCurrentUser).toBeCalled(); + expect(fetchCurrentUser).toHaveBeenCalled(); expect($('#username').text()).toBe('Johnny Cash - Logged In'); }); ```