From 6f570ce8865af1ac43c99b471d8404a41886efd8 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 3 Oct 2022 17:14:25 +0300 Subject: [PATCH 1/4] chore(lint): use `jest/no-alias-methods` rule --- .eslintrc.cjs | 5 +- docs/ExpectAPI.md | 18 +- docs/GlobalAPI.md | 4 +- docs/MockFunctionAPI.md | 4 +- .../__tests__/tests.test.js | 2 +- .../__tests__/storage/track/Track.test.js | 2 +- .../storage/track/TrackExpected.test.js | 2 +- .../jquery/__tests__/display_user.test.js | 2 +- .../__tests__/fetch_current_user.test.js | 2 +- .../__tests__/infinite_timer_game.test.js | 6 +- examples/timer/__tests__/timer_game.test.js | 16 +- examples/typescript/__tests__/calc.test.ts | 14 +- .../expect/src/__tests__/matchers.test.js | 70 +++---- .../circusItFailingTestError.test.ts | 14 +- .../src/__tests__/circusItTestError.test.ts | 16 +- .../__tests__/circusItTodoTestError.test.ts | 6 +- .../src/__tests__/hooksError.test.ts | 4 +- .../src/__tests__/normalize.test.ts | 10 +- .../src/__tests__/readConfig.test.ts | 2 +- .../src/__tests__/readConfigs.test.ts | 2 +- .../src/__tests__/resolveConfigPath.test.ts | 16 +- .../src/__tests__/stringToBytes.test.ts | 12 +- .../__tests__/SnapshotInteractiveMode.test.js | 52 ++--- .../src/__tests__/TestScheduler.test.js | 126 +++++------ .../jest-core/src/__tests__/watch.test.js | 8 +- .../watchFilenamePatternMode.test.js | 4 +- .../watchTestNamePatternMode.test.js | 4 +- .../jest-each/src/__tests__/template.test.ts | 12 +- .../src/__tests__/legacyFakeTimers.test.ts | 2 +- .../src/__tests__/modernFakeTimers.test.ts | 2 +- .../src/__tests__/sinon-integration.test.ts | 8 +- packages/jest-globals/src/__tests__/index.ts | 2 +- .../src/__tests__/index.test.js | 22 +- .../src/crawlers/__tests__/node.test.js | 4 +- .../src/crawlers/__tests__/watchman.test.js | 12 +- .../src/__tests__/hooksError.test.ts | 4 +- .../src/__tests__/itTestError.test.ts | 12 +- .../src/__tests__/todoError.test.ts | 6 +- .../src/__tests__/CoverageWorker.test.js | 2 +- .../__tests__/GitHubActionsReporter.test.ts | 8 +- .../src/__tests__/getResultHeader.test.js | 2 +- .../src/__tests__/testRunner.test.ts | 6 +- .../src/__tests__/Runtime-statics.test.js | 4 +- .../src/__tests__/runtime_jest_fn.js | 12 +- .../__tests__/runtime_require_module.test.js | 4 +- .../runtime_require_module_or_mock.test.js | 6 +- .../src/__tests__/InlineSnapshots.test.ts | 6 +- .../src/__tests__/throwMatcher.test.ts | 6 +- .../jest-snapshot/src/__tests__/utils.test.ts | 12 +- .../src/__tests__/ScriptTransformer.test.ts | 197 ++++++++++-------- .../convertDescriptorToString.test.ts | 2 +- .../src/__tests__/deepCyclicCopy.test.ts | 2 +- .../src/__tests__/validate.test.ts | 8 +- .../jest-worker/src/__tests__/Farm.test.js | 4 +- .../src/__tests__/WorkerPool.test.js | 18 +- .../__tests__/ChildProcessWorker.test.js | 2 +- .../__tests__/NodeThreadsWorker.test.js | 2 +- .../workers/__tests__/WorkerEdgeCases.test.js | 6 +- .../src/__tests__/prettyFormat.test.ts | 4 +- .../versioned_docs/version-25.x/ExpectAPI.md | 18 +- .../versioned_docs/version-25.x/GlobalAPI.md | 4 +- .../version-25.x/MockFunctionAPI.md | 8 +- .../versioned_docs/version-26.x/ExpectAPI.md | 18 +- .../versioned_docs/version-26.x/GlobalAPI.md | 4 +- .../version-26.x/MockFunctionAPI.md | 8 +- .../versioned_docs/version-27.x/ExpectAPI.md | 18 +- .../versioned_docs/version-27.x/GlobalAPI.md | 4 +- .../version-27.x/MockFunctionAPI.md | 8 +- .../versioned_docs/version-28.x/ExpectAPI.md | 18 +- .../versioned_docs/version-28.x/GlobalAPI.md | 4 +- .../version-28.x/MockFunctionAPI.md | 4 +- .../versioned_docs/version-29.0/ExpectAPI.md | 18 +- .../versioned_docs/version-29.0/GlobalAPI.md | 4 +- .../version-29.0/MockFunctionAPI.md | 4 +- .../versioned_docs/version-29.1/ExpectAPI.md | 18 +- .../versioned_docs/version-29.1/GlobalAPI.md | 4 +- .../version-29.1/MockFunctionAPI.md | 4 +- 77 files changed, 498 insertions(+), 492 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index b35530bd86af..77ba58941ccd 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -162,13 +162,12 @@ module.exports = { ], env: {'jest/globals': true}, excludedFiles: ['**/__typetests__/**'], + extends: ['plugin:jest/style'], plugins: ['jest'], rules: { + 'jest/no-alias-methods': 'error', 'jest/no-focused-tests': 'error', 'jest/no-identical-title': 'error', - 'jest/prefer-to-be': 'error', - 'jest/prefer-to-contain': 'error', - 'jest/prefer-to-have-length': 'error', 'jest/valid-expect': 'error', }, }, diff --git a/docs/ExpectAPI.md b/docs/ExpectAPI.md index 8ecb0152a4da..54d2d16a9d48 100644 --- a/docs/ExpectAPI.md +++ b/docs/ExpectAPI.md @@ -503,7 +503,7 @@ it('transitions as expected', () => { test('map calls its argument with a non-null argument', () => { const mock = jest.fn(); [1].map(x => mock(x)); - expect(mock).toBeCalledWith(expect.anything()); + expect(mock).toHaveBeenCalledWith(expect.anything()); }); ``` @@ -520,7 +520,7 @@ function getCat(fn) { test('randocall calls its callback with a class instance', () => { const mock = jest.fn(); getCat(mock); - expect(mock).toBeCalledWith(expect.any(Cat)); + expect(mock).toHaveBeenCalledWith(expect.any(Cat)); }); function randocall(fn) { @@ -530,7 +530,7 @@ function randocall(fn) { test('randocall calls its callback with a number', () => { const mock = jest.fn(); randocall(mock); - expect(mock).toBeCalledWith(expect.any(Number)); + expect(mock).toHaveBeenCalledWith(expect.any(Number)); }); ``` @@ -709,7 +709,7 @@ For example, let's say that we expect an `onPress` function to be called with an test('onPress gets called with the right thing', () => { const onPress = jest.fn(); simulatePresses(onPress); - expect(onPress).toBeCalledWith( + expect(onPress).toHaveBeenCalledWith( expect.objectContaining({ x: expect.any(Number), y: expect.any(Number), @@ -1548,15 +1548,15 @@ test('throws on octopus', () => { } // Test that the error message says "yuck" somewhere: these are equivalent - expect(drinkOctopus).toThrowError(/yuck/); - expect(drinkOctopus).toThrowError('yuck'); + expect(drinkOctopus).toThrow(/yuck/); + expect(drinkOctopus).toThrow('yuck'); // Test the exact error message - expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/); - expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor')); + expect(drinkOctopus).toThrow(/^yuck, octopus flavor$/); + expect(drinkOctopus).toThrow(new Error('yuck, octopus flavor')); // Test that we get a DisgustingFlavorError - expect(drinkOctopus).toThrowError(DisgustingFlavorError); + expect(drinkOctopus).toThrow(DisgustingFlavorError); }); ``` diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 775d40d11d9c..6bcbacd0b68b 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -212,11 +212,11 @@ const binaryStringToNumber = binString => { describe('binaryStringToNumber', () => { describe('given an invalid binary string', () => { test('composed of non-numbers throws CustomError', () => { - expect(() => binaryStringToNumber('abc')).toThrowError(CustomError); + expect(() => binaryStringToNumber('abc')).toThrow(CustomError); }); test('with extra whitespace throws CustomError', () => { - expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError); + expect(() => binaryStringToNumber(' 100')).toThrow(CustomError); }); }); diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md index 43a95bb3192e..fef7d983aec6 100644 --- a/docs/MockFunctionAPI.md +++ b/docs/MockFunctionAPI.md @@ -548,8 +548,8 @@ test('calculate calls add', () => { // requiring `add`. calculate(mockAdd, 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` diff --git a/e2e/failureDetails-property/__tests__/tests.test.js b/e2e/failureDetails-property/__tests__/tests.test.js index 4602fe51c60b..58cc89cc6968 100644 --- a/e2e/failureDetails-property/__tests__/tests.test.js +++ b/e2e/failureDetails-property/__tests__/tests.test.js @@ -33,5 +33,5 @@ it('throws!', () => { }); test('promise rejection', async () => { - await expect(Promise.resolve(1)).rejects.toThrowError(); + await expect(Promise.resolve(1)).rejects.toThrow(); }); diff --git a/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js b/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js index 2a1737478788..be6c16f0c18f 100644 --- a/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js +++ b/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js @@ -10,5 +10,5 @@ jest.mock('@@storage/track/Track'); test('relative import', () => { const track = new Track(); - expect(track.someRandomFunction).not.toBeCalled(); + expect(track.someRandomFunction).not.toHaveBeenCalled(); }); diff --git a/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js b/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js index 86224f67fe7d..494d7056bdce 100644 --- a/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js +++ b/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js @@ -10,5 +10,5 @@ jest.mock('@@storage/track/Track'); test('through moduleNameMapper', () => { const track = new Track(); - expect(track.someRandomFunction).not.toBeCalled(); + expect(track.someRandomFunction).not.toHaveBeenCalled(); }); diff --git a/examples/jquery/__tests__/display_user.test.js b/examples/jquery/__tests__/display_user.test.js index 08ac7e710575..35704cc9221b 100644 --- a/examples/jquery/__tests__/display_user.test.js +++ b/examples/jquery/__tests__/display_user.test.js @@ -34,6 +34,6 @@ it('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/examples/jquery/__tests__/fetch_current_user.test.js b/examples/jquery/__tests__/fetch_current_user.test.js index 0ae9287f45bd..8c1a8f66595a 100644 --- a/examples/jquery/__tests__/fetch_current_user.test.js +++ b/examples/jquery/__tests__/fetch_current_user.test.js @@ -14,7 +14,7 @@ it('calls into $.ajax with the correct params', () => { // Now make sure that $.ajax was properly called during the previous // 2 lines - expect($.ajax).toBeCalledWith({ + expect($.ajax).toHaveBeenCalledWith({ success: expect.any(Function), type: 'GET', url: 'http://example.com/currentUser', diff --git a/examples/timer/__tests__/infinite_timer_game.test.js b/examples/timer/__tests__/infinite_timer_game.test.js index 9266ded414e2..e1c87f03d3b8 100644 --- a/examples/timer/__tests__/infinite_timer_game.test.js +++ b/examples/timer/__tests__/infinite_timer_game.test.js @@ -13,7 +13,7 @@ it('schedules a 10-second timer after 1 second', () => { // At this point in time, there should have been a single call to // setTimeout to schedule the end of the game in 1 second. - expect(setTimeout).toBeCalledTimes(1); + expect(setTimeout).toHaveBeenCalledTimes(1); expect(setTimeout).toHaveBeenNthCalledWith(1, expect.any(Function), 1000); // Fast forward and exhaust only currently pending timers @@ -21,10 +21,10 @@ it('schedules a 10-second timer after 1 second', () => { 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 - expect(setTimeout).toBeCalledTimes(2); + expect(setTimeout).toHaveBeenCalledTimes(2); expect(setTimeout).toHaveBeenNthCalledWith(2, expect.any(Function), 10000); }); diff --git a/examples/timer/__tests__/timer_game.test.js b/examples/timer/__tests__/timer_game.test.js index f7f94304f2e3..f54c4c115641 100644 --- a/examples/timer/__tests__/timer_game.test.js +++ b/examples/timer/__tests__/timer_game.test.js @@ -12,8 +12,8 @@ describe('timerGame', () => { const timerGame = require('../timerGame'); timerGame(); - expect(setTimeout).toBeCalledTimes(1); - expect(setTimeout).toBeCalledWith(expect.any(Function), 1000); + expect(setTimeout).toHaveBeenCalledTimes(1); + expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), 1000); }); it('calls the callback after 1 second via runAllTimers', () => { @@ -23,14 +23,14 @@ describe('timerGame', () => { 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).toBeCalledTimes(1); + expect(callback).toHaveBeenCalled(); + expect(callback).toHaveBeenCalledTimes(1); }); it('calls the callback after 1 second via advanceTimersByTime', () => { @@ -40,13 +40,13 @@ describe('timerGame', () => { 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).toBeCalledTimes(1); + expect(callback).toHaveBeenCalled(); + expect(callback).toHaveBeenCalledTimes(1); }); }); diff --git a/examples/typescript/__tests__/calc.test.ts b/examples/typescript/__tests__/calc.test.ts index 63e271efd359..b9366cc10f99 100644 --- a/examples/typescript/__tests__/calc.test.ts +++ b/examples/typescript/__tests__/calc.test.ts @@ -24,7 +24,7 @@ describe('calc - mocks', () => { const result = calc('Sub', [2, 2]); expect(result).toBe(0); - expect(mockSub).toBeCalledWith(2, 2); + expect(mockSub).toHaveBeenCalledWith(2, 2); }); it('returns result from sum', () => { @@ -34,7 +34,7 @@ describe('calc - mocks', () => { const result = calc('Sum', [1, 1]); expect(result).toBe(2); - expect(mockSum).toBeCalledWith(1, 1); + expect(mockSum).toHaveBeenCalledWith(1, 1); }); it('adds last result to memory', () => { @@ -47,7 +47,7 @@ describe('calc - mocks', () => { expect(sumResult).toBe(2); expect(memoryResult).toBe(2); - expect(MockMemory.prototype.add).toBeCalledWith(2); + expect(MockMemory.prototype.add).toHaveBeenCalledWith(2); }); it('subtracts last result to memory', () => { @@ -60,7 +60,7 @@ describe('calc - mocks', () => { expect(sumResult).toBe(2); expect(memoryResult).toBe(2); - expect(MockMemory.prototype.subtract).toBeCalledWith(2); + expect(MockMemory.prototype.subtract).toHaveBeenCalledWith(2); }); it('clears the memory', () => { @@ -77,15 +77,13 @@ describe('calc - mocks', () => { expect(memoryResult).toBe(2); expect(sumResult2).toBe(4); expect(clearResult).toBe(4); - expect(MockMemory.prototype.reset).toBeCalledTimes(1); + expect(MockMemory.prototype.reset).toHaveBeenCalledTimes(1); }); it('throws an error when invalid Op is passed', () => { const calc = makeCalc(memory); // @ts-expect-error - expect(() => calc('Multiply', [2, 3])).toThrowError( - new Error('Invalid op'), - ); + expect(() => calc('Multiply', [2, 3])).toThrow(new Error('Invalid op')); }); }); diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 39204ec611f9..d85497f21152 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -254,7 +254,7 @@ describe('.toBe()', () => { [{a: BigInt(1)}, {a: BigInt(1)}], ].forEach(([a, b]) => { it(`fails for: ${stringify(a)} and ${stringify(b)}`, () => { - expect(() => jestExpect(a).toBe(b)).toThrowError('toBe'); + expect(() => jestExpect(a).toBe(b)).toThrow('toBe'); }); }); @@ -266,7 +266,7 @@ describe('.toBe()', () => { [BigInt(1), BigInt('1')].forEach(v => { it(`fails for '${stringify(v)}' with '.not'`, () => { - expect(() => jestExpect(v).not.toBe(v)).toThrowError('toBe'); + expect(() => jestExpect(v).not.toBe(v)).toThrow('toBe'); }); }); @@ -699,7 +699,7 @@ describe('.toEqual()', () => { test(`{pass: false} expect(${stringify(a)}).toEqual(${stringify( b, )})`, () => { - expect(() => jestExpect(a).toEqual(b)).toThrowError('toEqual'); + expect(() => jestExpect(a).toEqual(b)).toThrow('toEqual'); jestExpect(a).not.toEqual(b); }); }); @@ -953,7 +953,7 @@ describe('.toEqual()', () => { b, )})`, () => { jestExpect(a).toEqual(b); - expect(() => jestExpect(a).not.toEqual(b)).toThrowError('toEqual'); + expect(() => jestExpect(a).not.toEqual(b)).toThrow('toEqual'); }); }); @@ -1165,9 +1165,9 @@ describe('.toBeTruthy(), .toBeFalsy()', () => { jestExpect(v).toBeTruthy(); jestExpect(v).not.toBeFalsy(); - expect(() => jestExpect(v).not.toBeTruthy()).toThrowError('toBeTruthy'); + expect(() => jestExpect(v).not.toBeTruthy()).toThrow('toBeTruthy'); - expect(() => jestExpect(v).toBeFalsy()).toThrowError('toBeFalsy'); + expect(() => jestExpect(v).toBeFalsy()).toThrow('toBeFalsy'); }); }); @@ -1189,9 +1189,9 @@ describe('.toBeTruthy(), .toBeFalsy()', () => { jestExpect(v).toBeFalsy(); jestExpect(v).not.toBeTruthy(); - expect(() => jestExpect(v).toBeTruthy()).toThrowError('toBeTruthy'); + expect(() => jestExpect(v).toBeTruthy()).toThrow('toBeTruthy'); - expect(() => jestExpect(v).not.toBeFalsy()).toThrowError('toBeFalsy'); + expect(() => jestExpect(v).not.toBeFalsy()).toThrow('toBeFalsy'); }); }); }); @@ -1255,9 +1255,9 @@ describe('.toBeDefined(), .toBeUndefined()', () => { jestExpect(v).toBeDefined(); jestExpect(v).not.toBeUndefined(); - expect(() => jestExpect(v).not.toBeDefined()).toThrowError('toBeDefined'); + expect(() => jestExpect(v).not.toBeDefined()).toThrow('toBeDefined'); - expect(() => jestExpect(v).toBeUndefined()).toThrowError('toBeUndefined'); + expect(() => jestExpect(v).toBeUndefined()).toThrow('toBeUndefined'); }); }); @@ -1417,35 +1417,35 @@ describe( }); it(`throws: [${stringify(small)}, ${stringify(big)}]`, () => { - expect(() => jestExpect(small).toBeGreaterThan(big)).toThrowError( + expect(() => jestExpect(small).toBeGreaterThan(big)).toThrow( 'toBeGreaterThan', ); - expect(() => jestExpect(small).not.toBeLessThan(big)).toThrowError( + expect(() => jestExpect(small).not.toBeLessThan(big)).toThrow( 'toBeLessThan', ); - expect(() => jestExpect(big).not.toBeGreaterThan(small)).toThrowError( + expect(() => jestExpect(big).not.toBeGreaterThan(small)).toThrow( 'toBeGreaterThan', ); - expect(() => jestExpect(big).toBeLessThan(small)).toThrowError( + expect(() => jestExpect(big).toBeLessThan(small)).toThrow( 'toBeLessThan', ); - expect(() => - jestExpect(small).toBeGreaterThanOrEqual(big), - ).toThrowError('toBeGreaterThanOrEqual'); + expect(() => jestExpect(small).toBeGreaterThanOrEqual(big)).toThrow( + 'toBeGreaterThanOrEqual', + ); - expect(() => - jestExpect(small).not.toBeLessThanOrEqual(big), - ).toThrowError('toBeLessThanOrEqual'); + expect(() => jestExpect(small).not.toBeLessThanOrEqual(big)).toThrow( + 'toBeLessThanOrEqual', + ); - expect(() => - jestExpect(big).not.toBeGreaterThanOrEqual(small), - ).toThrowError('toBeGreaterThanOrEqual'); + expect(() => jestExpect(big).not.toBeGreaterThanOrEqual(small)).toThrow( + 'toBeGreaterThanOrEqual', + ); - expect(() => jestExpect(big).toBeLessThanOrEqual(small)).toThrowError( + expect(() => jestExpect(big).toBeLessThanOrEqual(small)).toThrow( 'toBeLessThanOrEqual', ); }); @@ -1480,11 +1480,11 @@ describe( jestExpect(n1).toBeGreaterThanOrEqual(n2); jestExpect(n1).toBeLessThanOrEqual(n2); - expect(() => - jestExpect(n1).not.toBeGreaterThanOrEqual(n2), - ).toThrowError('toBeGreaterThanOrEqual'); + expect(() => jestExpect(n1).not.toBeGreaterThanOrEqual(n2)).toThrow( + 'toBeGreaterThanOrEqual', + ); - expect(() => jestExpect(n1).not.toBeLessThanOrEqual(n2)).toThrowError( + expect(() => jestExpect(n1).not.toBeLessThanOrEqual(n2)).toThrow( 'toBeLessThanOrEqual', ); }); @@ -1510,10 +1510,8 @@ describe('.toContain(), .toContainEqual()', () => { jestExpect(iterable).toContain(2); jestExpect(iterable).toContainEqual(2); - expect(() => jestExpect(iterable).not.toContain(1)).toThrowError( - 'toContain', - ); - expect(() => jestExpect(iterable).not.toContainEqual(1)).toThrowError( + expect(() => jestExpect(iterable).not.toContain(1)).toThrow('toContain'); + expect(() => jestExpect(iterable).not.toContainEqual(1)).toThrow( 'toContainEqual', ); }); @@ -1545,7 +1543,7 @@ describe('.toContain(), .toContainEqual()', () => { it(`'${stringify(list)}' contains '${stringify(v)}'`, () => { jestExpect(list).toContain(v); - expect(() => jestExpect(list).not.toContain(v)).toThrowError('toContain'); + expect(() => jestExpect(list).not.toContain(v)).toThrow('toContain'); }); }); @@ -1568,7 +1566,7 @@ describe('.toContain(), .toContainEqual()', () => { it(`'${stringify(list)}' does not contain '${stringify(v)}'`, () => { jestExpect(list).not.toContain(v); - expect(() => jestExpect(list).toContain(v)).toThrowError('toContain'); + expect(() => jestExpect(list).toContain(v)).toThrow('toContain'); }); }); @@ -1584,9 +1582,7 @@ describe('.toContain(), .toContainEqual()', () => { expect(() => jestExpect('false').toContain(false), ).toThrowErrorMatchingSnapshot(); - expect(() => jestExpect('1').toContain(BigInt(1))).toThrowError( - 'toContain', - ); + expect(() => jestExpect('1').toContain(BigInt(1))).toThrow('toContain'); }); [ diff --git a/packages/jest-circus/src/__tests__/circusItFailingTestError.test.ts b/packages/jest-circus/src/__tests__/circusItFailingTestError.test.ts index 86c951ae48cc..0d2117dc1234 100644 --- a/packages/jest-circus/src/__tests__/circusItFailingTestError.test.ts +++ b/packages/jest-circus/src/__tests__/circusItFailingTestError.test.ts @@ -22,13 +22,13 @@ describe('test/it.failing error throwing', () => { it("it doesn't throw an error with valid arguments", () => { expect(() => { circusIt.failing('test1', () => {}); - }).not.toThrowError(); + }).not.toThrow(); }); it('it throws error with missing callback function', () => { expect(() => { // @ts-expect-error: Testing runtime errors here circusIt.failing('test2'); - }).toThrowError( + }).toThrow( 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.', ); }); @@ -36,7 +36,7 @@ describe('test/it.failing error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here circusIt.failing(() => {}); - }).toThrowError( + }).toThrow( 'Invalid first argument, () => {}. It must be a named class, named function, number, or string.', ); }); @@ -44,7 +44,7 @@ describe('test/it.failing error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here circusIt.failing('test4', 'test4b'); - }).toThrowError( + }).toThrow( 'Invalid second argument, test4b. It must be a callback function.', ); }); @@ -52,7 +52,7 @@ describe('test/it.failing error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here circusTest.failing('test5'); - }).toThrowError( + }).toThrow( 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.', ); }); @@ -60,7 +60,7 @@ describe('test/it.failing error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here circusTest.failing(() => {}); - }).toThrowError( + }).toThrow( 'Invalid first argument, () => {}. It must be a named class, named function, number, or string.', ); }); @@ -68,7 +68,7 @@ describe('test/it.failing error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here circusTest.failing('test7', 'test8b'); - }).toThrowError( + }).toThrow( 'Invalid second argument, test8b. It must be a callback function.', ); }); diff --git a/packages/jest-circus/src/__tests__/circusItTestError.test.ts b/packages/jest-circus/src/__tests__/circusItTestError.test.ts index f4f7a03d3611..36b1972c093a 100644 --- a/packages/jest-circus/src/__tests__/circusItTestError.test.ts +++ b/packages/jest-circus/src/__tests__/circusItTestError.test.ts @@ -25,13 +25,13 @@ describe('test/it error throwing', () => { it("it doesn't throw an error with valid arguments", () => { expect(() => { circusIt('test1', () => {}); - }).not.toThrowError(); + }).not.toThrow(); }); it('it throws error with missing callback function', () => { expect(() => { // @ts-expect-error: Easy, we're testing runtime errors here circusIt('test2'); - }).toThrowError( + }).toThrow( 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.', ); }); @@ -39,7 +39,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Easy, we're testing runtime errors here circusIt(() => {}); - }).toThrowError( + }).toThrow( 'Invalid first argument, () => {}. It must be a named class, named function, number, or string.', ); }); @@ -47,20 +47,20 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Easy, we're testing runtime errors here circusIt('test4', 'test4b'); - }).toThrowError( + }).toThrow( 'Invalid second argument, test4b. It must be a callback function.', ); }); it("test doesn't throw an error with valid arguments", () => { expect(() => { circusTest('test5', () => {}); - }).not.toThrowError(); + }).not.toThrow(); }); it('test throws error with missing callback function', () => { expect(() => { // @ts-expect-error: Easy, we're testing runtime errors here circusTest('test6'); - }).toThrowError( + }).toThrow( 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.', ); }); @@ -68,7 +68,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Easy, we're testing runtime errors here circusTest(() => {}); - }).toThrowError( + }).toThrow( 'Invalid first argument, () => {}. It must be a named class, named function, number, or string.', ); }); @@ -76,7 +76,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Easy, we're testing runtime errors here circusTest('test8', 'test8b'); - }).toThrowError( + }).toThrow( 'Invalid second argument, test8b. It must be a callback function.', ); }); diff --git a/packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts b/packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts index bcdc4ea1169e..8012e9c0198b 100644 --- a/packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts +++ b/packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts @@ -24,17 +24,17 @@ describe('test/it.todo error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here circusIt.todo(); - }).toThrowError('Todo must be called with only a description.'); + }).toThrow('Todo must be called with only a description.'); }); it('todo throws error when given more than one argument', () => { expect(() => { // @ts-expect-error: Testing runtime errors here circusIt.todo('test1', () => {}); - }).toThrowError('Todo must be called with only a description.'); + }).toThrow('Todo must be called with only a description.'); }); it('todo throws error when given none string description', () => { expect(() => { circusIt.todo(() => {}); - }).toThrowError('Todo must be called with only a description.'); + }).toThrow('Todo must be called with only a description.'); }); }); diff --git a/packages/jest-circus/src/__tests__/hooksError.test.ts b/packages/jest-circus/src/__tests__/hooksError.test.ts index 789aab96563b..3e38747b0c6d 100644 --- a/packages/jest-circus/src/__tests__/hooksError.test.ts +++ b/packages/jest-circus/src/__tests__/hooksError.test.ts @@ -29,9 +29,7 @@ describe.each([ expect(() => { // @ts-expect-error: Testing runtime errors here circus[fn](el); - }).toThrowError( - 'Invalid first argument. It must be a callback function.', - ); + }).toThrow('Invalid first argument. It must be a callback function.'); }, ); }); diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 74d515f65248..4b6f7e7dd41a 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -1059,9 +1059,7 @@ describe('preset', () => { }, {} as Config.Argv, ), - ).rejects.toThrowError( - /Cannot find module 'library-that-is-not-installed'/, - ); + ).rejects.toThrow(/Cannot find module 'library-that-is-not-installed'/); }); test('throws when preset is invalid', async () => { @@ -1077,7 +1075,7 @@ describe('preset', () => { }, {} as Config.Argv, ), - ).rejects.toThrowError( + ).rejects.toThrow( /Unexpected token } in JSON at position (104|110)[\s\S]* at /, ); }); @@ -1103,7 +1101,7 @@ describe('preset', () => { }, {} as Config.Argv, ), - ).rejects.toThrowError(errorMessage); + ).rejects.toThrow(errorMessage); }); test('works with "react-native"', async () => { @@ -1702,7 +1700,7 @@ describe('moduleFileExtensions', () => { }, {} as Config.Argv, ), - ).rejects.toThrowError("moduleFileExtensions must include 'js'"); + ).rejects.toThrow("moduleFileExtensions must include 'js'"); }, ); diff --git a/packages/jest-config/src/__tests__/readConfig.test.ts b/packages/jest-config/src/__tests__/readConfig.test.ts index 09cb362ecf49..112e927197bf 100644 --- a/packages/jest-config/src/__tests__/readConfig.test.ts +++ b/packages/jest-config/src/__tests__/readConfig.test.ts @@ -15,7 +15,7 @@ test('readConfig() throws when an object is passed without a file path', async ( false /* skipArgvConfigOption */, null /* parentConfigPath */, ), - ).rejects.toThrowError( + ).rejects.toThrow( 'Jest: Cannot use configuration as an object without a file path', ); }); diff --git a/packages/jest-config/src/__tests__/readConfigs.test.ts b/packages/jest-config/src/__tests__/readConfigs.test.ts index e6622d699f9b..6aa5a384b9f7 100644 --- a/packages/jest-config/src/__tests__/readConfigs.test.ts +++ b/packages/jest-config/src/__tests__/readConfigs.test.ts @@ -18,5 +18,5 @@ test('readConfigs() throws when called without project paths', async () => { await expect( // @ts-expect-error readConfigs(null /* argv */, [] /* projectPaths */), - ).rejects.toThrowError('jest: No configuration found for any project.'); + ).rejects.toThrow('jest: No configuration found for any project.'); }); diff --git a/packages/jest-config/src/__tests__/resolveConfigPath.test.ts b/packages/jest-config/src/__tests__/resolveConfigPath.test.ts index 167ab607bb31..515db568e6e9 100644 --- a/packages/jest-config/src/__tests__/resolveConfigPath.test.ts +++ b/packages/jest-config/src/__tests__/resolveConfigPath.test.ts @@ -32,7 +32,7 @@ describe.each(JEST_CONFIG_EXT_ORDER.slice(0))( expect(resolveConfigPath(absoluteConfigPath, DIR)).toBe( absoluteConfigPath, ); - expect(() => resolveConfigPath('/does_not_exist', DIR)).toThrowError( + expect(() => resolveConfigPath('/does_not_exist', DIR)).toThrow( NO_ROOT_DIR_ERROR_PATTERN, ); @@ -40,7 +40,7 @@ describe.each(JEST_CONFIG_EXT_ORDER.slice(0))( expect(resolveConfigPath(relativeConfigPath, DIR)).toBe( absoluteConfigPath, ); - expect(() => resolveConfigPath('does_not_exist', DIR)).toThrowError( + expect(() => resolveConfigPath('does_not_exist', DIR)).toThrow( NO_ROOT_DIR_ERROR_PATTERN, ); }); @@ -60,12 +60,12 @@ describe.each(JEST_CONFIG_EXT_ORDER.slice(0))( expect(() => // absolute resolveConfigPath(path.dirname(absoluteJestConfigPath), DIR), - ).toThrowError(ERROR_PATTERN); + ).toThrow(ERROR_PATTERN); expect(() => // relative resolveConfigPath(path.dirname(relativeJestConfigPath), DIR), - ).toThrowError(ERROR_PATTERN); + ).toThrow(ERROR_PATTERN); writeFiles(DIR, {[relativePackageJsonPath]: ''}); @@ -98,19 +98,19 @@ describe.each(JEST_CONFIG_EXT_ORDER.slice(0))( // absolute expect(() => resolveConfigPath(path.dirname(absolutePackageJsonPath), DIR), - ).toThrowError(MULTIPLE_CONFIGS_ERROR_PATTERN); + ).toThrow(MULTIPLE_CONFIGS_ERROR_PATTERN); // relative expect(() => resolveConfigPath(path.dirname(relativePackageJsonPath), DIR), - ).toThrowError(MULTIPLE_CONFIGS_ERROR_PATTERN); + ).toThrow(MULTIPLE_CONFIGS_ERROR_PATTERN); expect(() => { resolveConfigPath( path.join(path.dirname(relativePackageJsonPath), 'j/x/b/m/'), DIR, ); - }).toThrowError(NO_ROOT_DIR_ERROR_PATTERN); + }).toThrow(NO_ROOT_DIR_ERROR_PATTERN); }); }, ); @@ -146,7 +146,7 @@ describe.each(pickPairsWithSameOrder(JEST_CONFIG_EXT_ORDER))( expect(() => resolveConfigPath(path.dirname(relativeJestConfigPaths[0]), DIR), - ).toThrowError(MULTIPLE_CONFIGS_ERROR_PATTERN); + ).toThrow(MULTIPLE_CONFIGS_ERROR_PATTERN); }); }, ); diff --git a/packages/jest-config/src/__tests__/stringToBytes.test.ts b/packages/jest-config/src/__tests__/stringToBytes.test.ts index bebd0a32b2cc..c26cf5087a4c 100644 --- a/packages/jest-config/src/__tests__/stringToBytes.test.ts +++ b/packages/jest-config/src/__tests__/stringToBytes.test.ts @@ -21,11 +21,11 @@ describe('numeric input', () => { }); test('should throw when no reference supplied', () => { - expect(() => stringToBytes(0.3)).toThrowError(); + expect(() => stringToBytes(0.3)).toThrow(); }); test('should throw on a bad input', () => { - expect(() => stringToBytes(-0.3, 51)).toThrowError(); + expect(() => stringToBytes(-0.3, 51)).toThrow(); }); }); @@ -40,17 +40,17 @@ describe('string input', () => { }); test('should throw when no reference supplied', () => { - expect(() => stringToBytes('0.3')).toThrowError(); + expect(() => stringToBytes('0.3')).toThrow(); }); test('should throw on a bad input', () => { - expect(() => stringToBytes('-0.3', 51)).toThrowError(); + expect(() => stringToBytes('-0.3', 51)).toThrow(); }); }); describe('parsing', () => { test('0% should throw an error', () => { - expect(() => stringToBytes('0%', 51)).toThrowError(); + expect(() => stringToBytes('0%', 51)).toThrow(); }); test('30%', () => { @@ -109,7 +109,7 @@ describe('string input', () => { }); test('unknown unit', () => { - expect(() => stringToBytes('50XX')).toThrowError(); + expect(() => stringToBytes('50XX')).toThrow(); }); }); }); diff --git a/packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js b/packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js index 6e7135a87796..c9f2f8d0ef0f 100644 --- a/packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js +++ b/packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js @@ -38,7 +38,7 @@ describe('SnapshotInteractiveMode', () => { ]; instance.run(assertions, mockCallback); expect(instance.isActive()).toBeTruthy(); - expect(mockCallback).toBeCalledWith(assertions[0], false); + expect(mockCallback).toHaveBeenCalledWith(assertions[0], false); }); test('call to abort', () => { @@ -51,7 +51,7 @@ describe('SnapshotInteractiveMode', () => { instance.abort(); expect(instance.isActive()).toBeFalsy(); expect(instance.getSkippedNum()).toBe(0); - expect(mockCallback).toBeCalledWith(null, false); + expect(mockCallback).toHaveBeenCalledWith(null, false); }); test('call to reset', () => { @@ -64,7 +64,7 @@ describe('SnapshotInteractiveMode', () => { instance.restart(); expect(instance.isActive()).toBeTruthy(); expect(instance.getSkippedNum()).toBe(0); - expect(mockCallback).toBeCalledWith(assertions[0], false); + expect(mockCallback).toHaveBeenCalledWith(assertions[0], false); }); test('press Q or ESC triggers an abort', () => { @@ -86,7 +86,7 @@ describe('SnapshotInteractiveMode', () => { const assertions = [{fullName: 'test one', path: 'first.js'}]; instance.run(assertions, mockCallback); - expect(mockCallback).nthCalledWith(1, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(1, assertions[0], false); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); @@ -97,7 +97,7 @@ describe('SnapshotInteractiveMode', () => { instance.put('r'); expect(instance.getSkippedNum()).toBe(0); - expect(mockCallback).nthCalledWith(2, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(2, assertions[0], false); expect(mockCallback).toHaveBeenCalledTimes(2); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); }); @@ -106,7 +106,7 @@ describe('SnapshotInteractiveMode', () => { const assertions = [{fullName: 'test one', path: 'first.js'}]; instance.run(assertions, mockCallback); - expect(mockCallback).nthCalledWith(1, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(1, assertions[0], false); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); @@ -117,7 +117,7 @@ describe('SnapshotInteractiveMode', () => { instance.put('q'); expect(instance.getSkippedNum()).toBe(0); - expect(mockCallback).nthCalledWith(2, null, false); + expect(mockCallback).toHaveBeenNthCalledWith(2, null, false); expect(mockCallback).toHaveBeenCalledTimes(2); }); @@ -136,18 +136,18 @@ describe('SnapshotInteractiveMode', () => { const assertions = [{fullName: 'test one', path: 'first.js'}]; instance.run(assertions, mockCallback); - expect(mockCallback).nthCalledWith(1, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(1, assertions[0], false); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put('u'); - expect(mockCallback).nthCalledWith(2, assertions[0], true); + expect(mockCallback).toHaveBeenNthCalledWith(2, assertions[0], true); expect(mockCallback).toHaveBeenCalledTimes(2); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); instance.put(KEYS.ENTER); expect(instance.isActive()).toBe(false); - expect(mockCallback).nthCalledWith(3, null, false); + expect(mockCallback).toHaveBeenNthCalledWith(3, null, false); }); test('skip 2 tests, then finish and restart', () => { @@ -156,12 +156,12 @@ describe('SnapshotInteractiveMode', () => { {fullName: 'test two', path: 'first.js'}, ]; instance.run(assertions, mockCallback); - expect(mockCallback).nthCalledWith(1, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(1, assertions[0], false); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put('s'); - expect(mockCallback).nthCalledWith(2, assertions[1], false); + expect(mockCallback).toHaveBeenNthCalledWith(2, assertions[1], false); expect(mockCallback).toHaveBeenCalledTimes(2); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); @@ -173,7 +173,7 @@ describe('SnapshotInteractiveMode', () => { instance.put('r'); expect(instance.getSkippedNum()).toBe(0); - expect(mockCallback).nthCalledWith(3, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(3, assertions[0], false); expect(mockCallback).toHaveBeenCalledTimes(3); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); }); @@ -202,27 +202,27 @@ describe('SnapshotInteractiveMode', () => { ]; instance.run(assertions, mockCallback); - expect(mockCallback).nthCalledWith(1, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(1, assertions[0], false); expect(mockCallback).toHaveBeenCalledTimes(1); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put('u'); - expect(mockCallback).nthCalledWith(2, assertions[0], true); - expect(mockCallback).nthCalledWith(3, assertions[1], false); + expect(mockCallback).toHaveBeenNthCalledWith(2, assertions[0], true); + expect(mockCallback).toHaveBeenNthCalledWith(3, assertions[1], false); expect(mockCallback).toHaveBeenCalledTimes(3); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put('u'); - expect(mockCallback).nthCalledWith(4, assertions[1], true); + expect(mockCallback).toHaveBeenNthCalledWith(4, assertions[1], true); expect(mockCallback).toHaveBeenCalledTimes(4); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put(KEYS.ENTER); expect(instance.isActive()).toBe(false); - expect(mockCallback).nthCalledWith(5, null, false); + expect(mockCallback).toHaveBeenNthCalledWith(5, null, false); expect(mockCallback).toHaveBeenCalledTimes(5); }); @@ -250,14 +250,14 @@ describe('SnapshotInteractiveMode', () => { ]; instance.run(assertions, mockCallback); - expect(mockCallback).nthCalledWith(1, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(1, assertions[0], false); expect(mockCallback).toHaveBeenCalledTimes(1); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put('u'); - expect(mockCallback).nthCalledWith(2, assertions[0], true); - expect(mockCallback).nthCalledWith(3, assertions[1], false); + expect(mockCallback).toHaveBeenNthCalledWith(2, assertions[0], true); + expect(mockCallback).toHaveBeenNthCalledWith(3, assertions[1], false); expect(mockCallback).toHaveBeenCalledTimes(3); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); @@ -269,7 +269,7 @@ describe('SnapshotInteractiveMode', () => { instance.put('r'); expect(instance.getSkippedNum()).toBe(0); - expect(mockCallback).nthCalledWith(4, assertions[1], false); + expect(mockCallback).toHaveBeenNthCalledWith(4, assertions[1], false); expect(mockCallback).toHaveBeenCalledTimes(4); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); }); @@ -298,26 +298,26 @@ describe('SnapshotInteractiveMode', () => { ]; instance.run(assertions, mockCallback); - expect(mockCallback).nthCalledWith(1, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(1, assertions[0], false); expect(mockCallback).toHaveBeenCalledTimes(1); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put('s'); - expect(mockCallback).nthCalledWith(2, assertions[1], false); + expect(mockCallback).toHaveBeenNthCalledWith(2, assertions[1], false); expect(mockCallback).toHaveBeenCalledTimes(2); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put('u'); - expect(mockCallback).nthCalledWith(3, assertions[1], true); + expect(mockCallback).toHaveBeenNthCalledWith(3, assertions[1], true); expect(mockCallback).toHaveBeenCalledTimes(3); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); pipe.write.mockClear(); instance.put('r'); expect(instance.getSkippedNum()).toBe(0); - expect(mockCallback).nthCalledWith(4, assertions[0], false); + expect(mockCallback).toHaveBeenNthCalledWith(4, assertions[0], false); expect(mockCallback).toHaveBeenCalledTimes(4); expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot(); }); diff --git a/packages/jest-core/src/__tests__/TestScheduler.test.js b/packages/jest-core/src/__tests__/TestScheduler.test.js index 9425e2512f8f..d50517f34104 100644 --- a/packages/jest-core/src/__tests__/TestScheduler.test.js +++ b/packages/jest-core/src/__tests__/TestScheduler.test.js @@ -75,12 +75,12 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(1); - expect(VerboseReporter).toBeCalledTimes(0); - expect(GitHubActionsReporter).toBeCalledTimes(0); - expect(NotifyReporter).toBeCalledTimes(0); - expect(CoverageReporter).toBeCalledTimes(0); - expect(SummaryReporter).toBeCalledTimes(1); + expect(DefaultReporter).toHaveBeenCalledTimes(1); + expect(VerboseReporter).toHaveBeenCalledTimes(0); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(0); + expect(NotifyReporter).toHaveBeenCalledTimes(0); + expect(CoverageReporter).toHaveBeenCalledTimes(0); + expect(SummaryReporter).toHaveBeenCalledTimes(1); }); test('does not enable any reporters, if empty list is passed', async () => { @@ -92,12 +92,12 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(0); - expect(VerboseReporter).toBeCalledTimes(0); - expect(GitHubActionsReporter).toBeCalledTimes(0); - expect(NotifyReporter).toBeCalledTimes(0); - expect(CoverageReporter).toBeCalledTimes(0); - expect(SummaryReporter).toBeCalledTimes(0); + expect(DefaultReporter).toHaveBeenCalledTimes(0); + expect(VerboseReporter).toHaveBeenCalledTimes(0); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(0); + expect(NotifyReporter).toHaveBeenCalledTimes(0); + expect(CoverageReporter).toHaveBeenCalledTimes(0); + expect(SummaryReporter).toHaveBeenCalledTimes(0); }); test('sets up default reporters', async () => { @@ -109,12 +109,12 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(1); - expect(VerboseReporter).toBeCalledTimes(0); - expect(GitHubActionsReporter).toBeCalledTimes(0); - expect(NotifyReporter).toBeCalledTimes(0); - expect(CoverageReporter).toBeCalledTimes(0); - expect(SummaryReporter).toBeCalledTimes(1); + expect(DefaultReporter).toHaveBeenCalledTimes(1); + expect(VerboseReporter).toHaveBeenCalledTimes(0); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(0); + expect(NotifyReporter).toHaveBeenCalledTimes(0); + expect(CoverageReporter).toHaveBeenCalledTimes(0); + expect(SummaryReporter).toHaveBeenCalledTimes(1); }); test('sets up verbose reporter', async () => { @@ -127,12 +127,12 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(0); - expect(VerboseReporter).toBeCalledTimes(1); - expect(GitHubActionsReporter).toBeCalledTimes(0); - expect(NotifyReporter).toBeCalledTimes(0); - expect(CoverageReporter).toBeCalledTimes(0); - expect(SummaryReporter).toBeCalledTimes(1); + expect(DefaultReporter).toHaveBeenCalledTimes(0); + expect(VerboseReporter).toHaveBeenCalledTimes(1); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(0); + expect(NotifyReporter).toHaveBeenCalledTimes(0); + expect(CoverageReporter).toHaveBeenCalledTimes(0); + expect(SummaryReporter).toHaveBeenCalledTimes(1); }); test('sets up github actions reporter', async () => { @@ -147,12 +147,12 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(1); - expect(VerboseReporter).toBeCalledTimes(0); - expect(GitHubActionsReporter).toBeCalledTimes(1); - expect(NotifyReporter).toBeCalledTimes(0); - expect(CoverageReporter).toBeCalledTimes(0); - expect(SummaryReporter).toBeCalledTimes(1); + expect(DefaultReporter).toHaveBeenCalledTimes(1); + expect(VerboseReporter).toHaveBeenCalledTimes(0); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(1); + expect(NotifyReporter).toHaveBeenCalledTimes(0); + expect(CoverageReporter).toHaveBeenCalledTimes(0); + expect(SummaryReporter).toHaveBeenCalledTimes(1); }); test('sets up notify reporter', async () => { @@ -165,12 +165,12 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(1); - expect(VerboseReporter).toBeCalledTimes(0); - expect(GitHubActionsReporter).toBeCalledTimes(0); - expect(NotifyReporter).toBeCalledTimes(1); - expect(CoverageReporter).toBeCalledTimes(0); - expect(SummaryReporter).toBeCalledTimes(1); + expect(DefaultReporter).toHaveBeenCalledTimes(1); + expect(VerboseReporter).toHaveBeenCalledTimes(0); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(0); + expect(NotifyReporter).toHaveBeenCalledTimes(1); + expect(CoverageReporter).toHaveBeenCalledTimes(0); + expect(SummaryReporter).toHaveBeenCalledTimes(1); }); test('sets up coverage reporter', async () => { @@ -183,12 +183,12 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(1); - expect(VerboseReporter).toBeCalledTimes(0); - expect(GitHubActionsReporter).toBeCalledTimes(0); - expect(NotifyReporter).toBeCalledTimes(0); - expect(CoverageReporter).toBeCalledTimes(1); - expect(SummaryReporter).toBeCalledTimes(1); + expect(DefaultReporter).toHaveBeenCalledTimes(1); + expect(VerboseReporter).toHaveBeenCalledTimes(0); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(0); + expect(NotifyReporter).toHaveBeenCalledTimes(0); + expect(CoverageReporter).toHaveBeenCalledTimes(1); + expect(SummaryReporter).toHaveBeenCalledTimes(1); }); test('allows enabling summary reporter separately', async () => { @@ -200,12 +200,12 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(0); - expect(VerboseReporter).toBeCalledTimes(0); - expect(GitHubActionsReporter).toBeCalledTimes(0); - expect(NotifyReporter).toBeCalledTimes(0); - expect(CoverageReporter).toBeCalledTimes(0); - expect(SummaryReporter).toBeCalledTimes(1); + expect(DefaultReporter).toHaveBeenCalledTimes(0); + expect(VerboseReporter).toHaveBeenCalledTimes(0); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(0); + expect(NotifyReporter).toHaveBeenCalledTimes(0); + expect(CoverageReporter).toHaveBeenCalledTimes(0); + expect(SummaryReporter).toHaveBeenCalledTimes(1); }); test('sets up custom reporter', async () => { @@ -220,13 +220,13 @@ describe('reporters', () => { {}, ); - expect(DefaultReporter).toBeCalledTimes(1); - expect(VerboseReporter).toBeCalledTimes(0); - expect(GitHubActionsReporter).toBeCalledTimes(0); - expect(NotifyReporter).toBeCalledTimes(0); - expect(CoverageReporter).toBeCalledTimes(0); - expect(SummaryReporter).toBeCalledTimes(1); - expect(CustomReporter).toBeCalledTimes(1); + expect(DefaultReporter).toHaveBeenCalledTimes(1); + expect(VerboseReporter).toHaveBeenCalledTimes(0); + expect(GitHubActionsReporter).toHaveBeenCalledTimes(0); + expect(NotifyReporter).toHaveBeenCalledTimes(0); + expect(CoverageReporter).toHaveBeenCalledTimes(0); + expect(SummaryReporter).toHaveBeenCalledTimes(1); + expect(CustomReporter).toHaveBeenCalledTimes(1); }); }); @@ -281,8 +281,8 @@ describe('scheduleTests should always dispatch runStart and runComplete events', expect(result.numTotalTestSuites).toBe(1); - expect(mockReporter.onRunStart).toBeCalledTimes(1); - expect(mockReporter.onRunComplete).toBeCalledTimes(1); + expect(mockReporter.onRunStart).toHaveBeenCalledTimes(1); + expect(mockReporter.onRunComplete).toHaveBeenCalledTimes(1); const aggregatedResult = mockReporter.onRunComplete.mock.calls[0][1]; expect(aggregatedResult.runExecError).toBeUndefined(); @@ -315,8 +315,8 @@ describe('scheduleTests should always dispatch runStart and runComplete events', }), ).rejects.toEqual(runtimeError); - expect(mockReporter.onRunStart).toBeCalledTimes(1); - expect(mockReporter.onRunComplete).toBeCalledTimes(1); + expect(mockReporter.onRunStart).toHaveBeenCalledTimes(1); + expect(mockReporter.onRunComplete).toHaveBeenCalledTimes(1); const aggregatedResult = mockReporter.onRunComplete.mock.calls[0][1]; expect(aggregatedResult.runExecError.message).toEqual(message); expect(aggregatedResult.runExecError.stack.length).toBeGreaterThan(0); @@ -351,8 +351,8 @@ describe('scheduleTests should always dispatch runStart and runComplete events', expect(e).toEqual(errorMsg); } - expect(mockReporter.onRunStart).toBeCalledTimes(1); - expect(mockReporter.onRunComplete).toBeCalledTimes(1); + expect(mockReporter.onRunStart).toHaveBeenCalledTimes(1); + expect(mockReporter.onRunComplete).toHaveBeenCalledTimes(1); const aggregatedResult = mockReporter.onRunComplete.mock.calls[0][1]; if (hasExecError) { @@ -446,7 +446,7 @@ test('should bail after `n` failures', async () => { snapshot: {}, testResults: [{}], }); - expect(setState).toBeCalledWith({interrupted: true}); + expect(setState).toHaveBeenCalledWith({interrupted: true}); }); test('should not bail if less than `n` failures', async () => { @@ -482,7 +482,7 @@ test('should not bail if less than `n` failures', async () => { snapshot: {}, testResults: [{}], }); - expect(setState).not.toBeCalled(); + expect(setState).not.toHaveBeenCalled(); }); test('should set runInBand to run in serial', async () => { diff --git a/packages/jest-core/src/__tests__/watch.test.js b/packages/jest-core/src/__tests__/watch.test.js index ef803a2d0a1e..a8e505a8f469 100644 --- a/packages/jest-core/src/__tests__/watch.test.js +++ b/packages/jest-core/src/__tests__/watch.test.js @@ -416,7 +416,7 @@ describe('Watch mode flows', () => { hasteMapInstances, stdin, ), - ).rejects.toThrowError( + ).rejects.toThrow( new RegExp( `Watch plugin OffendingWatchPlugin attempted to register key <${key}>,\\s+that is reserved internally for .+\\.\\s+Please change the configuration key for this plugin\\.`, 'm', @@ -505,7 +505,7 @@ describe('Watch mode flows', () => { hasteMapInstances, stdin, ), - ).rejects.toThrowError( + ).rejects.toThrow( /Watch plugins OffendingFooThirdPartyWatchPlugin and OffendingBarThirdPartyWatchPlugin both attempted to register key \.\s+Please change the key configuration for one of the conflicting plugins to avoid overlap\./m, ); }); @@ -817,7 +817,7 @@ describe('Watch mode flows', () => { stdin.emit('o'); - expect(runJestMock).toBeCalled(); + expect(runJestMock).toHaveBeenCalled(); expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({ onlyChanged: true, watch: true, @@ -831,7 +831,7 @@ describe('Watch mode flows', () => { stdin.emit('a'); - expect(runJestMock).toBeCalled(); + expect(runJestMock).toHaveBeenCalled(); expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({ onlyChanged: false, watch: false, diff --git a/packages/jest-core/src/__tests__/watchFilenamePatternMode.test.js b/packages/jest-core/src/__tests__/watchFilenamePatternMode.test.js index cde9694f668e..fd636625d45f 100644 --- a/packages/jest-core/src/__tests__/watchFilenamePatternMode.test.js +++ b/packages/jest-core/src/__tests__/watchFilenamePatternMode.test.js @@ -93,7 +93,7 @@ describe('Watch mode flows', () => { // Write a enter pattern mode stdin.emit('p'); - expect(pipe.write).toBeCalledWith(' pattern › '); + expect(pipe.write).toHaveBeenCalledWith(' pattern › '); const assertPattern = hex => { pipe.write.mockReset(); @@ -111,7 +111,7 @@ describe('Watch mode flows', () => { // Runs Jest again runJestMock.mockReset(); stdin.emit(KEYS.ENTER); - expect(runJestMock).toBeCalled(); + expect(runJestMock).toHaveBeenCalled(); // globalConfig is updated with the current pattern expect(runJestMock.mock.calls[0][0].globalConfig).toMatchSnapshot(); diff --git a/packages/jest-core/src/__tests__/watchTestNamePatternMode.test.js b/packages/jest-core/src/__tests__/watchTestNamePatternMode.test.js index 9c7987b0bd56..1a8f525494ca 100644 --- a/packages/jest-core/src/__tests__/watchTestNamePatternMode.test.js +++ b/packages/jest-core/src/__tests__/watchTestNamePatternMode.test.js @@ -107,7 +107,7 @@ describe('Watch mode flows', () => { // Write a enter pattern mode stdin.emit('t'); - expect(pipe.write).toBeCalledWith(' pattern › '); + expect(pipe.write).toHaveBeenCalledWith(' pattern › '); const assertPattern = hex => { pipe.write.mockReset(); @@ -125,7 +125,7 @@ describe('Watch mode flows', () => { // Runs Jest again runJestMock.mockReset(); stdin.emit(KEYS.ENTER); - expect(runJestMock).toBeCalled(); + expect(runJestMock).toHaveBeenCalled(); // globalConfig is updated with the current pattern expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({ diff --git a/packages/jest-each/src/__tests__/template.test.ts b/packages/jest-each/src/__tests__/template.test.ts index ea98a58347a6..aa77e902b2e8 100644 --- a/packages/jest-each/src/__tests__/template.test.ts +++ b/packages/jest-each/src/__tests__/template.test.ts @@ -87,9 +87,7 @@ describe('jest-each', () => { const globalMock = get(globalTestMocks, keyPath); - expect(() => - jest.mocked(globalMock).mock.calls[0][1](), - ).not.toThrowError(); + expect(() => jest.mocked(globalMock).mock.calls[0][1]()).not.toThrow(); expect(testCallBack).toHaveBeenCalledWith({ b: 1, expected: 2, @@ -127,9 +125,7 @@ describe('jest-each', () => { const globalMock = get(globalTestMocks, keyPath); - expect(() => - jest.mocked(globalMock).mock.calls[0][1](), - ).not.toThrowError(); + expect(() => jest.mocked(globalMock).mock.calls[0][1]()).not.toThrow(); expect(testCallBack).toHaveBeenCalledWith({ a: 1, expected: 2, @@ -167,9 +163,7 @@ describe('jest-each', () => { const globalMock = get(globalTestMocks, keyPath); - expect(() => - jest.mocked(globalMock).mock.calls[0][1](), - ).not.toThrowError(); + expect(() => jest.mocked(globalMock).mock.calls[0][1]()).not.toThrow(); expect(testCallBack).toHaveBeenCalledWith({ '(๑ఠ‿ఠ๑)<expected': 2, a: 1, diff --git a/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts b/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts index da55d3be8163..b1921b856d7c 100644 --- a/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts +++ b/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts @@ -1118,7 +1118,7 @@ describe('FakeTimers', () => { }, 0); timers.runOnlyPendingTimers(); - expect(fn).not.toBeCalled(); + expect(fn).not.toHaveBeenCalled(); }); }); diff --git a/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts b/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts index 7df20e46e6eb..65cad21ccf6e 100644 --- a/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts +++ b/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts @@ -738,7 +738,7 @@ describe('FakeTimers', () => { }, 0); timers.runOnlyPendingTimers(); - expect(fn).not.toBeCalled(); + expect(fn).not.toHaveBeenCalled(); }); }); diff --git a/packages/jest-fake-timers/src/__tests__/sinon-integration.test.ts b/packages/jest-fake-timers/src/__tests__/sinon-integration.test.ts index 528e2d15937c..c845bad2568e 100644 --- a/packages/jest-fake-timers/src/__tests__/sinon-integration.test.ts +++ b/packages/jest-fake-timers/src/__tests__/sinon-integration.test.ts @@ -49,7 +49,7 @@ describe('`@sinonjs/fake-timers` integration', () => { timers.useFakeTimers(); - expect(mockInstall).toBeCalledWith({ + expect(mockInstall).toHaveBeenCalledWith({ advanceTimeDelta: undefined, loopLimit: 100_000, now: 123456, @@ -86,7 +86,7 @@ describe('`@sinonjs/fake-timers` integration', () => { timers.useFakeTimers(); - expect(mockInstall).toBeCalledWith({ + expect(mockInstall).toHaveBeenCalledWith({ advanceTimeDelta: undefined, loopLimit: 100, now: 0, @@ -119,7 +119,7 @@ describe('`@sinonjs/fake-timers` integration', () => { timerLimit: 2000, }); - expect(mockInstall).toBeCalledWith({ + expect(mockInstall).toHaveBeenCalledWith({ advanceTimeDelta: 40, loopLimit: 2000, now: new Date('1995-12-17'), @@ -158,7 +158,7 @@ describe('`@sinonjs/fake-timers` integration', () => { now: 123456, }); - expect(mockInstall).toBeCalledWith({ + expect(mockInstall).toHaveBeenCalledWith({ advanceTimeDelta: undefined, loopLimit: 1000, now: 123456, diff --git a/packages/jest-globals/src/__tests__/index.ts b/packages/jest-globals/src/__tests__/index.ts index cb0af7398581..3cd8f7797b06 100644 --- a/packages/jest-globals/src/__tests__/index.ts +++ b/packages/jest-globals/src/__tests__/index.ts @@ -6,7 +6,7 @@ */ test('throw when directly imported', () => { - expect(() => require('../')).toThrowError( + expect(() => require('../')).toThrow( 'Do not import `@jest/globals` outside of the Jest test environment', ); }); diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index 57a5809bafe0..b93a752a096d 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -693,7 +693,7 @@ describe('HasteMap', () => { expect(data.map.get('IRequireAVideo')).toBeDefined(); expect(data.files.get(path.join('video', 'video.mp4'))).toBeDefined(); - expect(fs.readFileSync).not.toBeCalledWith( + expect(fs.readFileSync).not.toHaveBeenCalledWith( path.join('video', 'video.mp4'), 'utf8', ); @@ -904,9 +904,9 @@ describe('HasteMap', () => { ).build(); expect(fs.readFileSync).toHaveBeenCalledTimes(1); if (require('v8').deserialize) { - expect(fs.readFileSync).toBeCalledWith(cacheFilePath); + expect(fs.readFileSync).toHaveBeenCalledWith(cacheFilePath); } else { - expect(fs.readFileSync).toBeCalledWith(cacheFilePath, 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith(cacheFilePath, 'utf8'); } expect(useBuitinsInContext(data.clocks)).toEqual(mockClocks); expect(useBuitinsInContext(data.files)).toEqual(initialData.files); @@ -939,11 +939,11 @@ describe('HasteMap', () => { expect(fs.readFileSync).toHaveBeenCalledTimes(2); if (require('v8').serialize) { - expect(fs.readFileSync).toBeCalledWith(cacheFilePath); + expect(fs.readFileSync).toHaveBeenCalledWith(cacheFilePath); } else { - expect(fs.readFileSync).toBeCalledWith(cacheFilePath, 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith(cacheFilePath, 'utf8'); } - expect(fs.readFileSync).toBeCalledWith( + expect(fs.readFileSync).toHaveBeenCalledWith( path.join('/', 'project', 'fruits', 'Banana.js'), 'utf8', ); @@ -1336,7 +1336,7 @@ describe('HasteMap', () => { ], ]); - expect(mockEnd).toBeCalled(); + expect(mockEnd).toHaveBeenCalled(); }); it('tries to crawl using node as a fallback', async () => { @@ -1360,8 +1360,8 @@ describe('HasteMap', () => { const {__hasteMapForTest: data} = await ( await HasteMap.create(defaultConfig) ).build(); - expect(watchman).toBeCalled(); - expect(node).toBeCalled(); + expect(watchman).toHaveBeenCalled(); + expect(node).toHaveBeenCalled(); expect(data.files).toEqual( createMap({ @@ -1401,8 +1401,8 @@ describe('HasteMap', () => { await HasteMap.create(defaultConfig) ).build(); - expect(watchman).toBeCalled(); - expect(node).toBeCalled(); + expect(watchman).toHaveBeenCalled(); + expect(node).toHaveBeenCalled(); expect(data.files).toEqual( createMap({ diff --git a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js index 7a0e9442fda5..d5bb7bf9a3a0 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js @@ -159,7 +159,7 @@ describe('node crawler', () => { roots: ['/project/fruits', '/project/vegetables'], }); - expect(childProcess.spawn).lastCalledWith('find', [ + expect(childProcess.spawn).toHaveBeenLastCalledWith('find', [ '/project/fruits', '/project/vegetables', '-type', @@ -266,7 +266,7 @@ describe('node crawler', () => { roots: ['/project/fruits'], }); - expect(childProcess.spawn).lastCalledWith( + expect(childProcess.spawn).toHaveBeenLastCalledWith( 'find', ['.', '-type', 'f', '(', '-iname', '*.ts', '-o', '-iname', '*.js', ')'], {cwd: expect.any(String)}, diff --git a/packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js b/packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js index 6b88f3e50f7c..777a5ed2ef7c 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js @@ -139,8 +139,8 @@ describe('watchman watch', () => { const client = watchman.Client.mock.instances[0]; const calls = client.command.mock.calls; - expect(client.on).toBeCalled(); - expect(client.on).toBeCalledWith('error', expect.any(Function)); + expect(client.on).toHaveBeenCalled(); + expect(client.on).toHaveBeenCalledWith('error', expect.any(Function)); // Call 0 and 1 are for ['watch-project'] expect(calls[0][0][0]).toBe('watch-project'); @@ -178,7 +178,7 @@ describe('watchman watch', () => { expect(removedFiles).toEqual(new Map()); - expect(client.end).toBeCalled(); + expect(client.end).toHaveBeenCalled(); }); test('updates file map and removedFiles when the clock is given', async () => { @@ -481,8 +481,8 @@ describe('watchman watch', () => { const client = watchman.Client.mock.instances[0]; const calls = client.command.mock.calls; - expect(client.on).toBeCalled(); - expect(client.on).toBeCalledWith('error', expect.any(Function)); + expect(client.on).toHaveBeenCalled(); + expect(client.on).toHaveBeenCalledWith('error', expect.any(Function)); // First 3 calls are for ['watch-project'] expect(calls[0][0][0]).toBe('watch-project'); @@ -515,7 +515,7 @@ describe('watchman watch', () => { expect(removedFiles).toEqual(new Map()); - expect(client.end).toBeCalled(); + expect(client.end).toHaveBeenCalled(); }); test('SHA-1 requested and available', async () => { diff --git a/packages/jest-jasmine2/src/__tests__/hooksError.test.ts b/packages/jest-jasmine2/src/__tests__/hooksError.test.ts index 9125f58df3f5..3355b74dda64 100644 --- a/packages/jest-jasmine2/src/__tests__/hooksError.test.ts +++ b/packages/jest-jasmine2/src/__tests__/hooksError.test.ts @@ -28,9 +28,7 @@ describe.each([ el => { expect(() => { globalThis[fn](el); - }).toThrowError( - 'Invalid first argument. It must be a callback function.', - ); + }).toThrow('Invalid first argument. It must be a callback function.'); }, ); }); diff --git a/packages/jest-jasmine2/src/__tests__/itTestError.test.ts b/packages/jest-jasmine2/src/__tests__/itTestError.test.ts index c4ec10d5ca09..e4c2add545dc 100644 --- a/packages/jest-jasmine2/src/__tests__/itTestError.test.ts +++ b/packages/jest-jasmine2/src/__tests__/itTestError.test.ts @@ -11,7 +11,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here it('test1'); - }).toThrowError( + }).toThrow( 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.', ); }); @@ -19,7 +19,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here it(() => {}); - }).toThrowError( + }).toThrow( 'Invalid first argument, () => {}. It must be a named class, named function, number, or string.', ); }); @@ -27,7 +27,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here it('test3', 'test3b'); - }).toThrowError( + }).toThrow( 'Invalid second argument, test3b. It must be a callback function.', ); }); @@ -35,7 +35,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here test('test4'); - }).toThrowError( + }).toThrow( 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.', ); }); @@ -43,7 +43,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here test(() => {}); - }).toThrowError( + }).toThrow( 'Invalid first argument, () => {}. It must be a named class, named function, number, or string.', ); }); @@ -51,7 +51,7 @@ describe('test/it error throwing', () => { expect(() => { // @ts-expect-error: Testing runtime errors here test('test6', 'test6b'); - }).toThrowError( + }).toThrow( 'Invalid second argument, test6b. It must be a callback function.', ); }); diff --git a/packages/jest-jasmine2/src/__tests__/todoError.test.ts b/packages/jest-jasmine2/src/__tests__/todoError.test.ts index cd875cfbefb8..285f1e01fd54 100644 --- a/packages/jest-jasmine2/src/__tests__/todoError.test.ts +++ b/packages/jest-jasmine2/src/__tests__/todoError.test.ts @@ -11,17 +11,17 @@ describe('test/it.todo error throwing', () => { expect(() => { // @ts-expect-error it.todo(); - }).toThrowError('Todo must be called with only a description.'); + }).toThrow('Todo must be called with only a description.'); }); it('it throws error when given more than one argument', () => { expect(() => { // @ts-expect-error: Testing runtime errors here it.todo('test1', () => {}); - }).toThrowError('Todo must be called with only a description.'); + }).toThrow('Todo must be called with only a description.'); }); it('it throws error when given none string description', () => { expect(() => { it.todo(() => {}); - }).toThrowError('Todo must be called with only a description.'); + }).toThrow('Todo must be called with only a description.'); }); }); diff --git a/packages/jest-reporters/src/__tests__/CoverageWorker.test.js b/packages/jest-reporters/src/__tests__/CoverageWorker.test.js index 0ea6f5a11799..21705f4c0d40 100644 --- a/packages/jest-reporters/src/__tests__/CoverageWorker.test.js +++ b/packages/jest-reporters/src/__tests__/CoverageWorker.test.js @@ -36,7 +36,7 @@ test('resolves to the result of generateEmptyCoverage upon success', async () => const result = await worker(workerOptions); - expect(generateEmptyCoverage).toBeCalledWith( + expect(generateEmptyCoverage).toHaveBeenCalledWith( validJS, 'banana.js', globalConfig, diff --git a/packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts b/packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts index 0a748797cfea..19ced0720956 100644 --- a/packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts +++ b/packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts @@ -83,7 +83,7 @@ describe('logs error annotation', () => { ], } as TestResult); - expect(mockedStderrWrite).toBeCalledTimes(1); + expect(mockedStderrWrite).toHaveBeenCalledTimes(1); expect(mockedStderrWrite.mock.calls[0]).toMatchSnapshot(); }); @@ -100,7 +100,7 @@ describe('logs error annotation', () => { } as TestResult, ); - expect(mockedStderrWrite).toBeCalledTimes(1); + expect(mockedStderrWrite).toHaveBeenCalledTimes(1); expect(mockedStderrWrite.mock.calls[0]).toMatchSnapshot(); }); @@ -114,7 +114,7 @@ describe('logs error annotation', () => { ], } as TestResult); - expect(mockedStderrWrite).toBeCalledTimes(1); + expect(mockedStderrWrite).toHaveBeenCalledTimes(1); expect(mockedStderrWrite.mock.calls[0]).toMatchSnapshot(); }); }); @@ -131,7 +131,7 @@ describe('logs warning annotation before logging errors', () => { ], } as TestResult); - expect(mockedStderrWrite).toBeCalledTimes(2); + expect(mockedStderrWrite).toHaveBeenCalledTimes(2); expect(mockedStderrWrite.mock.calls).toMatchSnapshot(); }); }); diff --git a/packages/jest-reporters/src/__tests__/getResultHeader.test.js b/packages/jest-reporters/src/__tests__/getResultHeader.test.js index 845b03ed4886..9c7efb001d67 100644 --- a/packages/jest-reporters/src/__tests__/getResultHeader.test.js +++ b/packages/jest-reporters/src/__tests__/getResultHeader.test.js @@ -45,7 +45,7 @@ beforeEach(() => { test('should call `terminal-link` correctly', () => { getResultHeader(testResult, globalConfig); - expect(terminalLink).toBeCalledWith( + expect(terminalLink).toHaveBeenCalledWith( expect.stringContaining('foo'), 'file:///foo', expect.objectContaining({fallback: expect.any(Function)}), diff --git a/packages/jest-runner/src/__tests__/testRunner.test.ts b/packages/jest-runner/src/__tests__/testRunner.test.ts index 85ee76e0f5d3..5d60f6511955 100644 --- a/packages/jest-runner/src/__tests__/testRunner.test.ts +++ b/packages/jest-runner/src/__tests__/testRunner.test.ts @@ -45,16 +45,16 @@ test('injects the serializable module map into each worker in watch mode', async {serial: false}, ); - expect(mockWorkerFarm.worker).toBeCalledTimes(2); + expect(mockWorkerFarm.worker).toHaveBeenCalledTimes(2); - expect(mockWorkerFarm.worker).nthCalledWith(1, { + expect(mockWorkerFarm.worker).toHaveBeenNthCalledWith(1, { config, context: runContext, globalConfig, path: './file.test.js', }); - expect(mockWorkerFarm.worker).nthCalledWith(2, { + expect(mockWorkerFarm.worker).toHaveBeenNthCalledWith(2, { config, context: runContext, globalConfig, diff --git a/packages/jest-runtime/src/__tests__/Runtime-statics.test.js b/packages/jest-runtime/src/__tests__/Runtime-statics.test.js index 849e332a82f7..ee2ca1f5124a 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-statics.test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-statics.test.js @@ -26,7 +26,7 @@ describe('Runtime statics', () => { test('Runtime.createHasteMap passes correct ignore files to HasteMap', async () => { await Runtime.createHasteMap(projectConfig, options); - expect(HasteMap.create).toBeCalledWith( + expect(HasteMap.create).toHaveBeenCalledWith( expect.objectContaining({ ignorePattern: /\/root\/ignore-1|\/root\/ignore-2/, }), @@ -35,7 +35,7 @@ describe('Runtime statics', () => { test('Runtime.createHasteMap passes correct ignore files to HasteMap in watch mode', async () => { await Runtime.createHasteMap(projectConfig, {...options, watch: true}); - expect(HasteMap.create).toBeCalledWith( + expect(HasteMap.create).toHaveBeenCalledWith( expect.objectContaining({ ignorePattern: /\/root\/ignore-1|\/root\/ignore-2|\/watch-root\/ignore-1/, diff --git a/packages/jest-runtime/src/__tests__/runtime_jest_fn.js b/packages/jest-runtime/src/__tests__/runtime_jest_fn.js index 705fe1fc10c7..a85322f97644 100644 --- a/packages/jest-runtime/src/__tests__/runtime_jest_fn.js +++ b/packages/jest-runtime/src/__tests__/runtime_jest_fn.js @@ -22,7 +22,7 @@ describe('Runtime', () => { const mock = root.jest.fn(); expect(mock._isMockFunction).toBe(true); mock(); - expect(mock).toBeCalled(); + expect(mock).toHaveBeenCalled(); }); it('creates mock functions with mock implementations', async () => { @@ -32,7 +32,7 @@ describe('Runtime', () => { expect(mock._isMockFunction).toBe(true); const value = mock('mock'); expect(value).toBe('mock implementation'); - expect(mock).toBeCalled(); + expect(mock).toHaveBeenCalled(); }); }); @@ -57,13 +57,13 @@ describe('Runtime', () => { const mock2 = root.jest.fn(); mock2(); - expect(mock1).toBeCalled(); - expect(mock2).toBeCalled(); + expect(mock1).toHaveBeenCalled(); + expect(mock2).toHaveBeenCalled(); runtime.clearAllMocks(); - expect(mock1).not.toBeCalled(); - expect(mock2).not.toBeCalled(); + expect(mock1).not.toHaveBeenCalled(); + expect(mock2).not.toHaveBeenCalled(); }); }); }); diff --git a/packages/jest-runtime/src/__tests__/runtime_require_module.test.js b/packages/jest-runtime/src/__tests__/runtime_require_module.test.js index d3cdb864bf9c..93582af47c3b 100644 --- a/packages/jest-runtime/src/__tests__/runtime_require_module.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_require_module.test.js @@ -366,10 +366,10 @@ describe('Runtime requireModule', () => { const runtime = await createRuntime(__filename); expect(() => runtime.requireModule(runtime.__mockRootPath, 'throwing'), - ).toThrowError(); + ).toThrow(); expect(() => runtime.requireModule(runtime.__mockRootPath, 'throwing'), - ).toThrowError(); + ).toThrow(); }); it('overrides module.createRequire', async () => { diff --git a/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js b/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js index 1eec78350149..8e28832c9d6a 100644 --- a/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js @@ -187,7 +187,7 @@ it('unmocks virtual mocks after they have been mocked previously', async () => { expect(() => { runtime.requireModuleOrMock(runtime.__mockRootPath, 'my-virtual-module'); - }).toThrowError( + }).toThrow( new Error("Cannot find module 'my-virtual-module' from 'root.js'"), ); }); @@ -271,7 +271,7 @@ describe('isolateModules', () => { runtime.isolateModules(() => { throw new Error('Error from isolated module'); }), - ).toThrowError('Error from isolated module'); + ).toThrow('Error from isolated module'); runtime.isolateModules(() => { expect(true).toBe(true); @@ -286,7 +286,7 @@ describe('isolateModules', () => { runtime.isolateModules(() => { runtime.isolateModules(() => {}); }); - }).toThrowError( + }).toThrow( 'isolateModules cannot be nested inside another isolateModules.', ); }); diff --git a/packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts b/packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts index fb7ac24fd812..0d924fda83e7 100644 --- a/packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts +++ b/packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts @@ -359,7 +359,7 @@ test('saveInlineSnapshots() throws if frame does not match', () => { 'prettier', ); - expect(save).toThrowError(/Couldn't locate all inline snapshots./); + expect(save).toThrow(/Couldn't locate all inline snapshots./); }); test('saveInlineSnapshots() throws if multiple calls to to the same location', () => { @@ -377,7 +377,7 @@ test('saveInlineSnapshots() throws if multiple calls to to the same location', ( 'prettier', ); - expect(save).toThrowError( + expect(save).toThrow( /Multiple inline snapshots for the same call are not supported./, ); }); @@ -719,7 +719,7 @@ test('saveInlineSnapshots() prioritize parser from project/editor configuration' 'prettier', ); - expect(prettierSpy).not.toBeCalled(); + expect(prettierSpy).not.toHaveBeenCalled(); expect(fs.readFileSync(filename, 'utf-8')).toBe( 'const foo = {\n' + ' "1": "Some value",\n' + diff --git a/packages/jest-snapshot/src/__tests__/throwMatcher.test.ts b/packages/jest-snapshot/src/__tests__/throwMatcher.test.ts index 94a201d87757..6b2897e8188d 100644 --- a/packages/jest-snapshot/src/__tests__/throwMatcher.test.ts +++ b/packages/jest-snapshot/src/__tests__/throwMatcher.test.ts @@ -30,7 +30,7 @@ it('throw matcher can take func', () => { false, ); - expect(mockedMatch).toBeCalledTimes(1); + expect(mockedMatch).toHaveBeenCalledTimes(1); expect(mockedMatch).toHaveBeenCalledWith( expect.objectContaining({received: 'coconut', testName: ''}), ); @@ -45,7 +45,7 @@ describe('throw matcher from promise', () => { true, ); - expect(mockedMatch).toBeCalledTimes(1); + expect(mockedMatch).toHaveBeenCalledTimes(1); expect(mockedMatch).toHaveBeenCalledWith( expect.objectContaining({received: 'coco', testName: ''}), ); @@ -61,7 +61,7 @@ describe('throw matcher from promise', () => { true, ); - expect(mockedMatch).toBeCalledTimes(1); + expect(mockedMatch).toHaveBeenCalledTimes(1); expect(mockedMatch).toHaveBeenCalledWith( expect.objectContaining({received: 'nut', testName: ''}), ); diff --git a/packages/jest-snapshot/src/__tests__/utils.test.ts b/packages/jest-snapshot/src/__tests__/utils.test.ts index 3f918a3cbeba..7d6cc062e03e 100644 --- a/packages/jest-snapshot/src/__tests__/utils.test.ts +++ b/packages/jest-snapshot/src/__tests__/utils.test.ts @@ -32,7 +32,7 @@ import { test('keyToTestName()', () => { expect(keyToTestName('abc cde 12')).toBe('abc cde'); expect(keyToTestName('abc cde 12')).toBe('abc cde '); - expect(() => keyToTestName('abc cde')).toThrowError( + expect(() => keyToTestName('abc cde')).toThrow( 'Snapshot keys must end with a number.', ); }); @@ -49,7 +49,7 @@ test('saveSnapshotFile() works with \r\n', () => { }; saveSnapshotFile(data, filename); - expect(fs.writeFileSync).toBeCalledWith( + expect(fs.writeFileSync).toHaveBeenCalledWith( filename, `// Jest Snapshot v1, ${SNAPSHOT_GUIDE_LINK}\n\n` + 'exports[`myKey`] = `
\n
`;\n', @@ -63,7 +63,7 @@ test('saveSnapshotFile() works with \r', () => { }; saveSnapshotFile(data, filename); - expect(fs.writeFileSync).toBeCalledWith( + expect(fs.writeFileSync).toHaveBeenCalledWith( filename, `// Jest Snapshot v1, ${SNAPSHOT_GUIDE_LINK}\n\n` + 'exports[`myKey`] = `
\n
`;\n', @@ -77,7 +77,7 @@ test('getSnapshotData() throws when no snapshot version', () => { .mockImplementation(() => 'exports[`myKey`] = `
\n
`;\n'); const update = 'none'; - expect(() => getSnapshotData(filename, update)).toThrowError( + expect(() => getSnapshotData(filename, update)).toThrow( chalk.red( `${chalk.bold('Outdated snapshot')}: No snapshot header found. ` + 'Jest 19 introduced versioned snapshots to ensure all developers on ' + @@ -98,7 +98,7 @@ test('getSnapshotData() throws for older snapshot version', () => { ); const update = 'none'; - expect(() => getSnapshotData(filename, update)).toThrowError( + expect(() => getSnapshotData(filename, update)).toThrow( `${chalk.red( `${chalk.red.bold('Outdated snapshot')}: The version of the snapshot ` + 'file associated with this test is outdated. The snapshot file ' + @@ -121,7 +121,7 @@ test('getSnapshotData() throws for newer snapshot version', () => { ); const update = 'none'; - expect(() => getSnapshotData(filename, update)).toThrowError( + expect(() => getSnapshotData(filename, update)).toThrow( `${chalk.red( `${chalk.red.bold('Outdated Jest version')}: The version of this ` + 'snapshot file indicates that this project is meant to be used ' + diff --git a/packages/jest-transform/src/__tests__/ScriptTransformer.test.ts b/packages/jest-transform/src/__tests__/ScriptTransformer.test.ts index 82e1711d8f7e..9c21c19eeb8d 100644 --- a/packages/jest-transform/src/__tests__/ScriptTransformer.test.ts +++ b/packages/jest-transform/src/__tests__/ScriptTransformer.test.ts @@ -301,7 +301,7 @@ describe('ScriptTransformer', () => { // no-cache case expect(fs.readFileSync).toHaveBeenCalledTimes(1); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); // in-memory cache const transformedBananaWithCoverageAgain = scriptTransformer.transform( @@ -346,7 +346,7 @@ describe('ScriptTransformer', () => { // no-cache case expect(fs.readFileSync).toHaveBeenCalledTimes(1); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); // in-memory cache const transformedBananaWithCoverageAgain = @@ -561,7 +561,7 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); - expect(require('test_preprocessor').getCacheKey).toBeCalled(); + expect(require('test_preprocessor').getCacheKey).toHaveBeenCalled(); expect(res1.code).toMatchSnapshot(); @@ -581,7 +581,7 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); - expect(require('test_preprocessor').getCacheKey).toBeCalled(); + expect(require('test_preprocessor').getCacheKey).toHaveBeenCalled(); expect(res1.code).toMatchSnapshot(); @@ -604,7 +604,9 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); - expect(require('test_async_preprocessor').getCacheKeyAsync).toBeCalled(); + expect( + require('test_async_preprocessor').getCacheKeyAsync, + ).toHaveBeenCalled(); expect(res1.code).toMatchSnapshot(); @@ -635,8 +637,8 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); - expect(require('test_preprocessor').getCacheKey).toBeCalled(); - expect(require('css-preprocessor').getCacheKey).toBeCalled(); + expect(require('test_preprocessor').getCacheKey).toHaveBeenCalled(); + expect(require('css-preprocessor').getCacheKey).toHaveBeenCalled(); expect(res1.code).toMatchSnapshot(); expect(res2.code).toMatchSnapshot(); @@ -667,8 +669,10 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); - expect(require('test_async_preprocessor').getCacheKeyAsync).toBeCalled(); - expect(require('css-preprocessor').getCacheKey).toBeCalled(); + expect( + require('test_async_preprocessor').getCacheKeyAsync, + ).toHaveBeenCalled(); + expect(require('css-preprocessor').getCacheKey).toHaveBeenCalled(); expect(res1.code).toMatchSnapshot(); expect(res2.code).toMatchSnapshot(); @@ -703,11 +707,15 @@ describe('ScriptTransformer', () => { ); expect(result.sourceMapPath).toEqual(expect.any(String)); const mapStr = JSON.stringify(map); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith(result.sourceMapPath, mapStr, { - encoding: 'utf8', - fsync: false, - }); + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( + result.sourceMapPath, + mapStr, + { + encoding: 'utf8', + fsync: false, + }, + ); }); it('in async mode, writes source map if preprocessor supplies it', async () => { @@ -733,11 +741,15 @@ describe('ScriptTransformer', () => { ); expect(result.sourceMapPath).toEqual(expect.any(String)); const mapStr = JSON.stringify(map); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith(result.sourceMapPath, mapStr, { - encoding: 'utf8', - fsync: false, - }); + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( + result.sourceMapPath, + mapStr, + { + encoding: 'utf8', + fsync: false, + }, + ); }); it('in async mode, writes source map if async preprocessor supplies it', async () => { @@ -765,11 +777,15 @@ describe('ScriptTransformer', () => { ); expect(result.sourceMapPath).toEqual(expect.any(String)); const mapStr = JSON.stringify(map); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith(result.sourceMapPath, mapStr, { - encoding: 'utf8', - fsync: false, - }); + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( + result.sourceMapPath, + mapStr, + { + encoding: 'utf8', + fsync: false, + }, + ); }); it('writes source map if preprocessor inlines it', async () => { @@ -799,8 +815,8 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, sourceMap, {encoding: 'utf8', fsync: false}, @@ -834,8 +850,8 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, sourceMap, {encoding: 'utf8', fsync: false}, @@ -869,8 +885,8 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, sourceMap, {encoding: 'utf8', fsync: false}, @@ -910,7 +926,7 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toBeNull(); - expect(writeFileAtomic.sync).toBeCalledTimes(1); + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(1); expect(console.warn).toHaveBeenCalledTimes(1); expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); @@ -950,7 +966,7 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toBeNull(); - expect(writeFileAtomic.sync).toBeCalledTimes(1); + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(1); expect(console.warn).toHaveBeenCalledTimes(1); expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); @@ -990,7 +1006,7 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toBeNull(); - expect(writeFileAtomic.sync).toBeCalledTimes(1); + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(1); expect(console.warn).toHaveBeenCalledTimes(1); expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); @@ -1020,8 +1036,8 @@ describe('ScriptTransformer', () => { getCoverageOptions(), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, JSON.stringify(map), { @@ -1127,8 +1143,8 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, JSON.stringify(instrumentedCodeMap), expect.anything(), @@ -1172,8 +1188,8 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, JSON.stringify(instrumentedCodeMap), expect.anything(), @@ -1219,8 +1235,8 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, JSON.stringify(instrumentedCodeMap), expect.anything(), @@ -1255,8 +1271,8 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, JSON.stringify(instrumentedCodeMap), expect.anything(), @@ -1291,8 +1307,8 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, JSON.stringify(instrumentedCodeMap), expect.anything(), @@ -1329,8 +1345,8 @@ describe('ScriptTransformer', () => { getCoverageOptions({collectCoverage: true}), ); expect(result.sourceMapPath).toEqual(expect.any(String)); - expect(writeFileAtomic.sync).toBeCalledTimes(2); - expect(writeFileAtomic.sync).toBeCalledWith( + expect(writeFileAtomic.sync).toHaveBeenCalledTimes(2); + expect(writeFileAtomic.sync).toHaveBeenCalledWith( result.sourceMapPath, JSON.stringify(instrumentedCodeMap), expect.anything(), @@ -1412,7 +1428,7 @@ describe('ScriptTransformer', () => { scriptTransformer.transform('/fruits/banana.js', getCoverageOptions()); const cachePath = getCachePath(mockFs, config); - expect(writeFileAtomic.sync).toBeCalled(); + expect(writeFileAtomic.sync).toHaveBeenCalled(); expect(writeFileAtomic.sync.mock.calls[0][0]).toBe(cachePath); // Cache the state in `mockFsCopy` @@ -1426,9 +1442,9 @@ describe('ScriptTransformer', () => { scriptTransformer.transform('/fruits/banana.js', getCoverageOptions()); expect(fs.readFileSync).toHaveBeenCalledTimes(2); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); - expect(fs.readFileSync).toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).not.toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).not.toHaveBeenCalled(); // Don't read from the cache when `config.cache` is false. jest.resetModules(); @@ -1439,9 +1455,9 @@ describe('ScriptTransformer', () => { scriptTransformer.transform('/fruits/banana.js', getCoverageOptions()); expect(fs.readFileSync).toHaveBeenCalledTimes(1); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); - expect(fs.readFileSync).not.toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).not.toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).toHaveBeenCalled(); }); it('in async mode, reads values from the cache', async () => { @@ -1456,7 +1472,7 @@ describe('ScriptTransformer', () => { ); const cachePath = getCachePath(mockFs, config); - expect(writeFileAtomic.sync).toBeCalled(); + expect(writeFileAtomic.sync).toHaveBeenCalled(); expect(writeFileAtomic.sync.mock.calls[0][0]).toBe(cachePath); // Cache the state in `mockFsCopy` @@ -1473,9 +1489,9 @@ describe('ScriptTransformer', () => { ); expect(fs.readFileSync).toHaveBeenCalledTimes(2); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); - expect(fs.readFileSync).toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).not.toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).not.toHaveBeenCalled(); // Don't read from the cache when `config.cache` is false. jest.resetModules(); @@ -1489,9 +1505,9 @@ describe('ScriptTransformer', () => { ); expect(fs.readFileSync).toHaveBeenCalledTimes(1); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); - expect(fs.readFileSync).not.toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).not.toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).toHaveBeenCalled(); }); it('reads values from the cache when using async preprocessor', async () => { @@ -1506,7 +1522,7 @@ describe('ScriptTransformer', () => { ); const cachePath = getCachePath(mockFs, config); - expect(writeFileAtomic.sync).toBeCalled(); + expect(writeFileAtomic.sync).toHaveBeenCalled(); expect(writeFileAtomic.sync.mock.calls[0][0]).toBe(cachePath); // Cache the state in `mockFsCopy` @@ -1523,9 +1539,9 @@ describe('ScriptTransformer', () => { ); expect(fs.readFileSync).toHaveBeenCalledTimes(2); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); - expect(fs.readFileSync).toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).not.toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).not.toHaveBeenCalled(); // Don't read from the cache when `config.cache` is false. jest.resetModules(); @@ -1539,9 +1555,9 @@ describe('ScriptTransformer', () => { ); expect(fs.readFileSync).toHaveBeenCalledTimes(1); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); - expect(fs.readFileSync).not.toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).not.toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).toHaveBeenCalled(); }); it('reads values from the cache when the file contains colons', async () => { @@ -1556,7 +1572,7 @@ describe('ScriptTransformer', () => { ); const cachePath = getCachePath(mockFs, config); - expect(writeFileAtomic.sync).toBeCalled(); + expect(writeFileAtomic.sync).toHaveBeenCalled(); expect(writeFileAtomic.sync.mock.calls[0][0]).toBe(cachePath); // Cache the state in `mockFsCopy` @@ -1570,9 +1586,12 @@ describe('ScriptTransformer', () => { scriptTransformer.transform('/fruits/banana:colon.js', {}); expect(fs.readFileSync).toHaveBeenCalledTimes(2); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana:colon.js', 'utf8'); - expect(fs.readFileSync).toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).not.toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith( + '/fruits/banana:colon.js', + 'utf8', + ); + expect(fs.readFileSync).toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).not.toHaveBeenCalled(); }); it('in async mode, reads values from the cache when the file contains colons', async () => { @@ -1587,7 +1606,7 @@ describe('ScriptTransformer', () => { ); const cachePath = getCachePath(mockFs, config); - expect(writeFileAtomic.sync).toBeCalled(); + expect(writeFileAtomic.sync).toHaveBeenCalled(); expect(writeFileAtomic.sync.mock.calls[0][0]).toBe(cachePath); // Cache the state in `mockFsCopy` @@ -1601,9 +1620,12 @@ describe('ScriptTransformer', () => { await scriptTransformer.transformAsync('/fruits/banana:colon.js', {}); expect(fs.readFileSync).toHaveBeenCalledTimes(2); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana:colon.js', 'utf8'); - expect(fs.readFileSync).toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).not.toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith( + '/fruits/banana:colon.js', + 'utf8', + ); + expect(fs.readFileSync).toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).not.toHaveBeenCalled(); }); it('with async preprocessor, reads values from the cache when the file contains colons', async () => { @@ -1618,7 +1640,7 @@ describe('ScriptTransformer', () => { ); const cachePath = getCachePath(mockFs, config); - expect(writeFileAtomic.sync).toBeCalled(); + expect(writeFileAtomic.sync).toHaveBeenCalled(); expect(writeFileAtomic.sync.mock.calls[0][0]).toBe(cachePath); // Cache the state in `mockFsCopy` @@ -1632,9 +1654,12 @@ describe('ScriptTransformer', () => { await scriptTransformer.transformAsync('/fruits/banana:colon.js', {}); expect(fs.readFileSync).toHaveBeenCalledTimes(2); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana:colon.js', 'utf8'); - expect(fs.readFileSync).toBeCalledWith(cachePath, 'utf8'); - expect(writeFileAtomic.sync).not.toBeCalled(); + expect(fs.readFileSync).toHaveBeenCalledWith( + '/fruits/banana:colon.js', + 'utf8', + ); + expect(fs.readFileSync).toHaveBeenCalledWith(cachePath, 'utf8'); + expect(writeFileAtomic.sync).not.toHaveBeenCalled(); }); it('should reuse the value from in-memory cache which is set by custom transformer', async () => { @@ -1659,7 +1684,7 @@ describe('ScriptTransformer', () => { expect(testPreprocessor.getCacheKey.mock.calls[0][2].cacheFS).toBeDefined(); expect(testPreprocessor.process.mock.calls[0][2].cacheFS).toBeDefined(); expect(fs.readFileSync).toHaveBeenCalledTimes(1); - expect(fs.readFileSync).toBeCalledWith(fileName1, 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith(fileName1, 'utf8'); }); it('in async mode, should reuse the value from in-memory cache which is set by custom preprocessor', async () => { @@ -1684,7 +1709,7 @@ describe('ScriptTransformer', () => { expect(testPreprocessor.getCacheKey.mock.calls[0][2].cacheFS).toBeDefined(); expect(testPreprocessor.process.mock.calls[0][2].cacheFS).toBeDefined(); expect(fs.readFileSync).toHaveBeenCalledTimes(1); - expect(fs.readFileSync).toBeCalledWith(fileName1, 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith(fileName1, 'utf8'); }); it('should reuse the value from in-memory cache which is set by custom async preprocessor', async () => { @@ -1713,7 +1738,7 @@ describe('ScriptTransformer', () => { testPreprocessor.processAsync.mock.calls[0][2].cacheFS, ).toBeDefined(); expect(fs.readFileSync).toHaveBeenCalledTimes(1); - expect(fs.readFileSync).toBeCalledWith(fileName1, 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith(fileName1, 'utf8'); }); it('does not reuse the in-memory cache between different projects', async () => { @@ -1735,7 +1760,7 @@ describe('ScriptTransformer', () => { ); expect(fs.readFileSync).toHaveBeenCalledTimes(2); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); }); it('async mode does not reuse the in-memory cache between different projects', async () => { @@ -1760,7 +1785,7 @@ describe('ScriptTransformer', () => { ); expect(fs.readFileSync).toHaveBeenCalledTimes(2); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); }); it('regardless of sync/async, does not reuse the in-memory cache between different projects', async () => { @@ -1800,7 +1825,7 @@ describe('ScriptTransformer', () => { ); expect(fs.readFileSync).toHaveBeenCalledTimes(4); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); + expect(fs.readFileSync).toHaveBeenCalledWith('/fruits/banana.js', 'utf8'); }); it('preload transformer when using `createScriptTransformer`', async () => { diff --git a/packages/jest-util/src/__tests__/convertDescriptorToString.test.ts b/packages/jest-util/src/__tests__/convertDescriptorToString.test.ts index 5aba082873a2..9c846fd60eca 100644 --- a/packages/jest-util/src/__tests__/convertDescriptorToString.test.ts +++ b/packages/jest-util/src/__tests__/convertDescriptorToString.test.ts @@ -29,7 +29,7 @@ describe(convertDescriptorToString, () => { expect(() => { // @ts-expect-error return convertDescriptorToString(input); - }).toThrowError( + }).toThrow( `Invalid first argument, ${input}. It must be a named class, named function, number, or string.`, ); }); diff --git a/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts b/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts index 518c9927657e..1f81c3202eae 100644 --- a/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts +++ b/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts @@ -31,7 +31,7 @@ it('does not execute getters/setters, but copies them', () => { const copy = deepCyclicCopy(obj); expect(Object.getOwnPropertyDescriptor(copy, 'foo')).toBeDefined(); - expect(fn).not.toBeCalled(); + expect(fn).not.toHaveBeenCalled(); }); it('copies symbols', () => { diff --git a/packages/jest-validate/src/__tests__/validate.test.ts b/packages/jest-validate/src/__tests__/validate.test.ts index ff0e8572ba13..72daeea9f53d 100644 --- a/packages/jest-validate/src/__tests__/validate.test.ts +++ b/packages/jest-validate/src/__tests__/validate.test.ts @@ -121,7 +121,7 @@ test('respects recursiveDenylist', () => { validate(config, {exampleConfig}); - expect(console.warn).toBeCalled(); + expect(console.warn).toHaveBeenCalled(); console.warn.mockReset(); @@ -130,7 +130,7 @@ test('respects recursiveDenylist', () => { recursiveDenylist: ['something.nested'], }); - expect(console.warn).not.toBeCalled(); + expect(console.warn).not.toHaveBeenCalled(); console.warn = warn; }); @@ -285,7 +285,7 @@ test('Comments in config JSON using "//" key are not warned', () => { validate(config, { exampleConfig: validConfig, }); - expect(console.warn).not.toBeCalled(); + expect(console.warn).not.toHaveBeenCalled(); console.warn.mockReset(); @@ -293,7 +293,7 @@ test('Comments in config JSON using "//" key are not warned', () => { exampleConfig: validConfig, recursiveDenylist: ['myCustomKey' as "don't validate this"], }); - expect(console.warn).not.toBeCalled(); + expect(console.warn).not.toHaveBeenCalled(); console.warn.mockRestore(); }); diff --git a/packages/jest-worker/src/__tests__/Farm.test.js b/packages/jest-worker/src/__tests__/Farm.test.js index dbab6ac1abc6..9ec84d1f67fb 100644 --- a/packages/jest-worker/src/__tests__/Farm.test.js +++ b/packages/jest-worker/src/__tests__/Farm.test.js @@ -111,7 +111,7 @@ describe('Farm', () => { workerReply(0); await p0; - expect(computeWorkerKey).toBeCalledTimes(1); + expect(computeWorkerKey).toHaveBeenCalledTimes(1); expect(computeWorkerKey).toHaveBeenNthCalledWith(1, 'foo', 42); expect(callback).toHaveBeenCalledTimes(1); @@ -146,7 +146,7 @@ describe('Farm', () => { workerReply(2); await p2; - expect(computeWorkerKey).toBeCalledTimes(3); + expect(computeWorkerKey).toHaveBeenCalledTimes(3); expect(computeWorkerKey).toHaveBeenNthCalledWith(1, 'foo', 42); expect(computeWorkerKey).toHaveBeenNthCalledWith(2, 'foo1', 43); expect(computeWorkerKey).toHaveBeenNthCalledWith(3, 'foo2', 44); diff --git a/packages/jest-worker/src/__tests__/WorkerPool.test.js b/packages/jest-worker/src/__tests__/WorkerPool.test.js index 91283ef514b8..1134eda510a6 100644 --- a/packages/jest-worker/src/__tests__/WorkerPool.test.js +++ b/packages/jest-worker/src/__tests__/WorkerPool.test.js @@ -57,14 +57,14 @@ describe('WorkerPool', () => { const onEnd = () => {}; workerPool.send(0, {foo: 'bar'}, onStart, onEnd); - expect(ChildProcessWorker).toBeCalledWith({ + expect(ChildProcessWorker).toHaveBeenCalledWith({ forkOptions: {}, maxRetries: 1, workerId: 0, workerPath: '/path', }); - expect(NodeThreadWorker).not.toBeCalled(); - expect(workerPool._workers[0].send).toBeCalledWith( + expect(NodeThreadWorker).not.toHaveBeenCalled(); + expect(workerPool._workers[0].send).toHaveBeenCalledWith( {foo: 'bar'}, onStart, onEnd, @@ -87,14 +87,14 @@ describe('WorkerPool', () => { const onEnd = () => {}; workerPool.send(0, {foo: 'bar'}, onStart, onEnd); - expect(NodeThreadWorker).toBeCalledWith({ + expect(NodeThreadWorker).toHaveBeenCalledWith({ forkOptions: {}, maxRetries: 1, workerId: 0, workerPath: '/path', }); - expect(ChildProcessWorker).not.toBeCalled(); - expect(workerPool._workers[0].send).toBeCalledWith( + expect(ChildProcessWorker).not.toHaveBeenCalled(); + expect(workerPool._workers[0].send).toHaveBeenCalledWith( {foo: 'bar'}, onStart, onEnd, @@ -116,14 +116,14 @@ describe('WorkerPool', () => { const onEnd = () => {}; workerPool.send(0, {foo: 'bar'}, onStart, onEnd); - expect(ChildProcessWorker).toBeCalledWith({ + expect(ChildProcessWorker).toHaveBeenCalledWith({ forkOptions: {}, maxRetries: 1, workerId: 0, workerPath: '/path', }); - expect(NodeThreadWorker).not.toBeCalled(); - expect(workerPool._workers[0].send).toBeCalledWith( + expect(NodeThreadWorker).not.toHaveBeenCalled(); + expect(workerPool._workers[0].send).toHaveBeenCalledWith( {foo: 'bar'}, onStart, onEnd, diff --git a/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js b/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js index 1464a38cdaf4..4159587e037e 100644 --- a/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js +++ b/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js @@ -137,7 +137,7 @@ it('stops initializing the worker after the amount of retries is exceeded', () = forkInterface.emit('exit', 1); expect(childProcess.fork).toHaveBeenCalledTimes(5); - expect(onProcessStart).toBeCalledWith(worker); + expect(onProcessStart).toHaveBeenCalledWith(worker); expect(onProcessEnd).toHaveBeenCalledTimes(1); expect(onProcessEnd.mock.calls[0][0]).toBeInstanceOf(Error); expect(onProcessEnd.mock.calls[0][0].type).toBe('WorkerError'); diff --git a/packages/jest-worker/src/workers/__tests__/NodeThreadsWorker.test.js b/packages/jest-worker/src/workers/__tests__/NodeThreadsWorker.test.js index 98278c25ecee..5ae5a814c2bd 100644 --- a/packages/jest-worker/src/workers/__tests__/NodeThreadsWorker.test.js +++ b/packages/jest-worker/src/workers/__tests__/NodeThreadsWorker.test.js @@ -121,7 +121,7 @@ it('stops initializing the worker after the amount of retries is exceeded', () = worker._worker.emit('exit'); expect(workerThreads).toHaveBeenCalledTimes(5); - expect(onProcessStart).toBeCalledWith(worker); + expect(onProcessStart).toHaveBeenCalledWith(worker); expect(onProcessEnd).toHaveBeenCalledTimes(1); expect(onProcessEnd.mock.calls[0][0]).toBeInstanceOf(Error); expect(onProcessEnd.mock.calls[0][0].type).toBe('WorkerError'); diff --git a/packages/jest-worker/src/workers/__tests__/WorkerEdgeCases.test.js b/packages/jest-worker/src/workers/__tests__/WorkerEdgeCases.test.js index cb87382792a4..6c6397d81d73 100644 --- a/packages/jest-worker/src/workers/__tests__/WorkerEdgeCases.test.js +++ b/packages/jest-worker/src/workers/__tests__/WorkerEdgeCases.test.js @@ -54,7 +54,7 @@ afterAll(async () => { test.each(filesToBuild)('%s.js should exist', async file => { const path = join(writeDestination, `${file}.js`); - await expect(async () => await access(path)).not.toThrowError(); + await expect(async () => await access(path)).not.toThrow(); }); async function closeWorkerAfter(worker, testBody) { @@ -317,7 +317,7 @@ describe.each([ test('worker stays dead', async () => { await expect( async () => await worker.waitForWorkerReady(), - ).rejects.toThrowError(); + ).rejects.toThrow(); expect(worker.isWorkerRunning()).toBeFalsy(); }); @@ -385,7 +385,7 @@ describe.each([ test('processes exits', async () => { worker.forceExit(); - await expect(() => worker.waitForWorkerReady()).rejects.toThrowError(); + await expect(() => worker.waitForWorkerReady()).rejects.toThrow(); }); }); }); diff --git a/packages/pretty-format/src/__tests__/prettyFormat.test.ts b/packages/pretty-format/src/__tests__/prettyFormat.test.ts index 75afa767a4c9..68aacd956760 100644 --- a/packages/pretty-format/src/__tests__/prettyFormat.test.ts +++ b/packages/pretty-format/src/__tests__/prettyFormat.test.ts @@ -894,8 +894,8 @@ describe('prettyFormat()', () => { ).toBe( `Set {\n Object {\n "apple": "banana",\n "toJSON": [Function ${name}],\n },\n}`, ); - expect((set as any).toJSON).not.toBeCalled(); - expect(value.toJSON).not.toBeCalled(); + expect((set as any).toJSON).not.toHaveBeenCalled(); + expect(value.toJSON).not.toHaveBeenCalled(); }); describe('min', () => { diff --git a/website/versioned_docs/version-25.x/ExpectAPI.md b/website/versioned_docs/version-25.x/ExpectAPI.md index 20bbd7e63e3b..ccb0d72e079e 100644 --- a/website/versioned_docs/version-25.x/ExpectAPI.md +++ b/website/versioned_docs/version-25.x/ExpectAPI.md @@ -367,7 +367,7 @@ it('transitions as expected', () => { test('map calls its argument with a non-null argument', () => { const mock = jest.fn(); [1].map(x => mock(x)); - expect(mock).toBeCalledWith(expect.anything()); + expect(mock).toHaveBeenCalledWith(expect.anything()); }); ``` @@ -384,7 +384,7 @@ function getCat(fn) { test('randocall calls its callback with a class instance', () => { const mock = jest.fn(); getCat(mock); - expect(mock).toBeCalledWith(expect.any(Cat)); + expect(mock).toHaveBeenCalledWith(expect.any(Cat)); }); function randocall(fn) { @@ -394,7 +394,7 @@ function randocall(fn) { test('randocall calls its callback with a number', () => { const mock = jest.fn(); randocall(mock); - expect(mock).toBeCalledWith(expect.any(Number)); + expect(mock).toHaveBeenCalledWith(expect.any(Number)); }); ``` @@ -553,7 +553,7 @@ For example, let's say that we expect an `onPress` function to be called with an test('onPress gets called with the right thing', () => { const onPress = jest.fn(); simulatePresses(onPress); - expect(onPress).toBeCalledWith( + expect(onPress).toHaveBeenCalledWith( expect.objectContaining({ x: expect.any(Number), y: expect.any(Number), @@ -1362,15 +1362,15 @@ test('throws on octopus', () => { } // Test that the error message says "yuck" somewhere: these are equivalent - expect(drinkOctopus).toThrowError(/yuck/); - expect(drinkOctopus).toThrowError('yuck'); + expect(drinkOctopus).toThrow(/yuck/); + expect(drinkOctopus).toThrow('yuck'); // Test the exact error message - expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/); - expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor')); + expect(drinkOctopus).toThrow(/^yuck, octopus flavor$/); + expect(drinkOctopus).toThrow(new Error('yuck, octopus flavor')); // Test that we get a DisgustingFlavorError - expect(drinkOctopus).toThrowError(DisgustingFlavorError); + expect(drinkOctopus).toThrow(DisgustingFlavorError); }); ``` diff --git a/website/versioned_docs/version-25.x/GlobalAPI.md b/website/versioned_docs/version-25.x/GlobalAPI.md index 04d9fae63e7f..0e31a5f11c58 100644 --- a/website/versioned_docs/version-25.x/GlobalAPI.md +++ b/website/versioned_docs/version-25.x/GlobalAPI.md @@ -208,11 +208,11 @@ const binaryStringToNumber = binString => { describe('binaryStringToNumber', () => { describe('given an invalid binary string', () => { test('composed of non-numbers throws CustomError', () => { - expect(() => binaryStringToNumber('abc')).toThrowError(CustomError); + expect(() => binaryStringToNumber('abc')).toThrow(CustomError); }); test('with extra whitespace throws CustomError', () => { - expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError); + expect(() => binaryStringToNumber(' 100')).toThrow(CustomError); }); }); diff --git a/website/versioned_docs/version-25.x/MockFunctionAPI.md b/website/versioned_docs/version-25.x/MockFunctionAPI.md index 8966e1d28856..a38fb7823436 100644 --- a/website/versioned_docs/version-25.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-25.x/MockFunctionAPI.md @@ -351,8 +351,8 @@ const mockAdd = add as jest.MockedFunction; test('calculate calls add', () => { calculate('Add', 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` @@ -387,8 +387,8 @@ test('calculate calls add', () => { // anything requiring `add`. calculate(mockAdd, 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` diff --git a/website/versioned_docs/version-26.x/ExpectAPI.md b/website/versioned_docs/version-26.x/ExpectAPI.md index 20bbd7e63e3b..ccb0d72e079e 100644 --- a/website/versioned_docs/version-26.x/ExpectAPI.md +++ b/website/versioned_docs/version-26.x/ExpectAPI.md @@ -367,7 +367,7 @@ it('transitions as expected', () => { test('map calls its argument with a non-null argument', () => { const mock = jest.fn(); [1].map(x => mock(x)); - expect(mock).toBeCalledWith(expect.anything()); + expect(mock).toHaveBeenCalledWith(expect.anything()); }); ``` @@ -384,7 +384,7 @@ function getCat(fn) { test('randocall calls its callback with a class instance', () => { const mock = jest.fn(); getCat(mock); - expect(mock).toBeCalledWith(expect.any(Cat)); + expect(mock).toHaveBeenCalledWith(expect.any(Cat)); }); function randocall(fn) { @@ -394,7 +394,7 @@ function randocall(fn) { test('randocall calls its callback with a number', () => { const mock = jest.fn(); randocall(mock); - expect(mock).toBeCalledWith(expect.any(Number)); + expect(mock).toHaveBeenCalledWith(expect.any(Number)); }); ``` @@ -553,7 +553,7 @@ For example, let's say that we expect an `onPress` function to be called with an test('onPress gets called with the right thing', () => { const onPress = jest.fn(); simulatePresses(onPress); - expect(onPress).toBeCalledWith( + expect(onPress).toHaveBeenCalledWith( expect.objectContaining({ x: expect.any(Number), y: expect.any(Number), @@ -1362,15 +1362,15 @@ test('throws on octopus', () => { } // Test that the error message says "yuck" somewhere: these are equivalent - expect(drinkOctopus).toThrowError(/yuck/); - expect(drinkOctopus).toThrowError('yuck'); + expect(drinkOctopus).toThrow(/yuck/); + expect(drinkOctopus).toThrow('yuck'); // Test the exact error message - expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/); - expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor')); + expect(drinkOctopus).toThrow(/^yuck, octopus flavor$/); + expect(drinkOctopus).toThrow(new Error('yuck, octopus flavor')); // Test that we get a DisgustingFlavorError - expect(drinkOctopus).toThrowError(DisgustingFlavorError); + expect(drinkOctopus).toThrow(DisgustingFlavorError); }); ``` diff --git a/website/versioned_docs/version-26.x/GlobalAPI.md b/website/versioned_docs/version-26.x/GlobalAPI.md index 11c26be64c2b..81c0c09865ac 100644 --- a/website/versioned_docs/version-26.x/GlobalAPI.md +++ b/website/versioned_docs/version-26.x/GlobalAPI.md @@ -208,11 +208,11 @@ const binaryStringToNumber = binString => { describe('binaryStringToNumber', () => { describe('given an invalid binary string', () => { test('composed of non-numbers throws CustomError', () => { - expect(() => binaryStringToNumber('abc')).toThrowError(CustomError); + expect(() => binaryStringToNumber('abc')).toThrow(CustomError); }); test('with extra whitespace throws CustomError', () => { - expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError); + expect(() => binaryStringToNumber(' 100')).toThrow(CustomError); }); }); diff --git a/website/versioned_docs/version-26.x/MockFunctionAPI.md b/website/versioned_docs/version-26.x/MockFunctionAPI.md index 8966e1d28856..a38fb7823436 100644 --- a/website/versioned_docs/version-26.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-26.x/MockFunctionAPI.md @@ -351,8 +351,8 @@ const mockAdd = add as jest.MockedFunction; test('calculate calls add', () => { calculate('Add', 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` @@ -387,8 +387,8 @@ test('calculate calls add', () => { // anything requiring `add`. calculate(mockAdd, 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` diff --git a/website/versioned_docs/version-27.x/ExpectAPI.md b/website/versioned_docs/version-27.x/ExpectAPI.md index a3c320e53436..a6f3dcee78f6 100644 --- a/website/versioned_docs/version-27.x/ExpectAPI.md +++ b/website/versioned_docs/version-27.x/ExpectAPI.md @@ -348,7 +348,7 @@ it('transitions as expected', () => { test('map calls its argument with a non-null argument', () => { const mock = jest.fn(); [1].map(x => mock(x)); - expect(mock).toBeCalledWith(expect.anything()); + expect(mock).toHaveBeenCalledWith(expect.anything()); }); ``` @@ -365,7 +365,7 @@ function getCat(fn) { test('randocall calls its callback with a class instance', () => { const mock = jest.fn(); getCat(mock); - expect(mock).toBeCalledWith(expect.any(Cat)); + expect(mock).toHaveBeenCalledWith(expect.any(Cat)); }); function randocall(fn) { @@ -375,7 +375,7 @@ function randocall(fn) { test('randocall calls its callback with a number', () => { const mock = jest.fn(); randocall(mock); - expect(mock).toBeCalledWith(expect.any(Number)); + expect(mock).toHaveBeenCalledWith(expect.any(Number)); }); ``` @@ -554,7 +554,7 @@ For example, let's say that we expect an `onPress` function to be called with an test('onPress gets called with the right thing', () => { const onPress = jest.fn(); simulatePresses(onPress); - expect(onPress).toBeCalledWith( + expect(onPress).toHaveBeenCalledWith( expect.objectContaining({ x: expect.any(Number), y: expect.any(Number), @@ -1377,15 +1377,15 @@ test('throws on octopus', () => { } // Test that the error message says "yuck" somewhere: these are equivalent - expect(drinkOctopus).toThrowError(/yuck/); - expect(drinkOctopus).toThrowError('yuck'); + expect(drinkOctopus).toThrow(/yuck/); + expect(drinkOctopus).toThrow('yuck'); // Test the exact error message - expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/); - expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor')); + expect(drinkOctopus).toThrow(/^yuck, octopus flavor$/); + expect(drinkOctopus).toThrow(new Error('yuck, octopus flavor')); // Test that we get a DisgustingFlavorError - expect(drinkOctopus).toThrowError(DisgustingFlavorError); + expect(drinkOctopus).toThrow(DisgustingFlavorError); }); ``` diff --git a/website/versioned_docs/version-27.x/GlobalAPI.md b/website/versioned_docs/version-27.x/GlobalAPI.md index 26185d0d9885..ae2c531986ce 100644 --- a/website/versioned_docs/version-27.x/GlobalAPI.md +++ b/website/versioned_docs/version-27.x/GlobalAPI.md @@ -208,11 +208,11 @@ const binaryStringToNumber = binString => { describe('binaryStringToNumber', () => { describe('given an invalid binary string', () => { test('composed of non-numbers throws CustomError', () => { - expect(() => binaryStringToNumber('abc')).toThrowError(CustomError); + expect(() => binaryStringToNumber('abc')).toThrow(CustomError); }); test('with extra whitespace throws CustomError', () => { - expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError); + expect(() => binaryStringToNumber(' 100')).toThrow(CustomError); }); }); diff --git a/website/versioned_docs/version-27.x/MockFunctionAPI.md b/website/versioned_docs/version-27.x/MockFunctionAPI.md index 06fe2512e33b..4a4023408653 100644 --- a/website/versioned_docs/version-27.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-27.x/MockFunctionAPI.md @@ -361,8 +361,8 @@ const mockAdd = add as jest.MockedFunction; test('calculate calls add', () => { calculate('Add', 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` @@ -397,8 +397,8 @@ test('calculate calls add', () => { // anything requiring `add`. calculate(mockAdd, 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` diff --git a/website/versioned_docs/version-28.x/ExpectAPI.md b/website/versioned_docs/version-28.x/ExpectAPI.md index 9c11287be932..377fd53a527d 100644 --- a/website/versioned_docs/version-28.x/ExpectAPI.md +++ b/website/versioned_docs/version-28.x/ExpectAPI.md @@ -371,7 +371,7 @@ it('transitions as expected', () => { test('map calls its argument with a non-null argument', () => { const mock = jest.fn(); [1].map(x => mock(x)); - expect(mock).toBeCalledWith(expect.anything()); + expect(mock).toHaveBeenCalledWith(expect.anything()); }); ``` @@ -388,7 +388,7 @@ function getCat(fn) { test('randocall calls its callback with a class instance', () => { const mock = jest.fn(); getCat(mock); - expect(mock).toBeCalledWith(expect.any(Cat)); + expect(mock).toHaveBeenCalledWith(expect.any(Cat)); }); function randocall(fn) { @@ -398,7 +398,7 @@ function randocall(fn) { test('randocall calls its callback with a number', () => { const mock = jest.fn(); randocall(mock); - expect(mock).toBeCalledWith(expect.any(Number)); + expect(mock).toHaveBeenCalledWith(expect.any(Number)); }); ``` @@ -577,7 +577,7 @@ For example, let's say that we expect an `onPress` function to be called with an test('onPress gets called with the right thing', () => { const onPress = jest.fn(); simulatePresses(onPress); - expect(onPress).toBeCalledWith( + expect(onPress).toHaveBeenCalledWith( expect.objectContaining({ x: expect.any(Number), y: expect.any(Number), @@ -1416,15 +1416,15 @@ test('throws on octopus', () => { } // Test that the error message says "yuck" somewhere: these are equivalent - expect(drinkOctopus).toThrowError(/yuck/); - expect(drinkOctopus).toThrowError('yuck'); + expect(drinkOctopus).toThrow(/yuck/); + expect(drinkOctopus).toThrow('yuck'); // Test the exact error message - expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/); - expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor')); + expect(drinkOctopus).toThrow(/^yuck, octopus flavor$/); + expect(drinkOctopus).toThrow(new Error('yuck, octopus flavor')); // Test that we get a DisgustingFlavorError - expect(drinkOctopus).toThrowError(DisgustingFlavorError); + expect(drinkOctopus).toThrow(DisgustingFlavorError); }); ``` diff --git a/website/versioned_docs/version-28.x/GlobalAPI.md b/website/versioned_docs/version-28.x/GlobalAPI.md index 42cdd9f9c872..2d085aa9d9b8 100644 --- a/website/versioned_docs/version-28.x/GlobalAPI.md +++ b/website/versioned_docs/version-28.x/GlobalAPI.md @@ -208,11 +208,11 @@ const binaryStringToNumber = binString => { describe('binaryStringToNumber', () => { describe('given an invalid binary string', () => { test('composed of non-numbers throws CustomError', () => { - expect(() => binaryStringToNumber('abc')).toThrowError(CustomError); + expect(() => binaryStringToNumber('abc')).toThrow(CustomError); }); test('with extra whitespace throws CustomError', () => { - expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError); + expect(() => binaryStringToNumber(' 100')).toThrow(CustomError); }); }); diff --git a/website/versioned_docs/version-28.x/MockFunctionAPI.md b/website/versioned_docs/version-28.x/MockFunctionAPI.md index 5a02bb5efc49..902a777f7464 100644 --- a/website/versioned_docs/version-28.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-28.x/MockFunctionAPI.md @@ -511,7 +511,7 @@ test('calculate calls add', () => { // requiring `add`. calculate(mockAdd, 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` diff --git a/website/versioned_docs/version-29.0/ExpectAPI.md b/website/versioned_docs/version-29.0/ExpectAPI.md index 88c4f944e973..3e85d193fa8b 100644 --- a/website/versioned_docs/version-29.0/ExpectAPI.md +++ b/website/versioned_docs/version-29.0/ExpectAPI.md @@ -352,7 +352,7 @@ it('transitions as expected', () => { test('map calls its argument with a non-null argument', () => { const mock = jest.fn(); [1].map(x => mock(x)); - expect(mock).toBeCalledWith(expect.anything()); + expect(mock).toHaveBeenCalledWith(expect.anything()); }); ``` @@ -369,7 +369,7 @@ function getCat(fn) { test('randocall calls its callback with a class instance', () => { const mock = jest.fn(); getCat(mock); - expect(mock).toBeCalledWith(expect.any(Cat)); + expect(mock).toHaveBeenCalledWith(expect.any(Cat)); }); function randocall(fn) { @@ -379,7 +379,7 @@ function randocall(fn) { test('randocall calls its callback with a number', () => { const mock = jest.fn(); randocall(mock); - expect(mock).toBeCalledWith(expect.any(Number)); + expect(mock).toHaveBeenCalledWith(expect.any(Number)); }); ``` @@ -558,7 +558,7 @@ For example, let's say that we expect an `onPress` function to be called with an test('onPress gets called with the right thing', () => { const onPress = jest.fn(); simulatePresses(onPress); - expect(onPress).toBeCalledWith( + expect(onPress).toHaveBeenCalledWith( expect.objectContaining({ x: expect.any(Number), y: expect.any(Number), @@ -1397,15 +1397,15 @@ test('throws on octopus', () => { } // Test that the error message says "yuck" somewhere: these are equivalent - expect(drinkOctopus).toThrowError(/yuck/); - expect(drinkOctopus).toThrowError('yuck'); + expect(drinkOctopus).toThrow(/yuck/); + expect(drinkOctopus).toThrow('yuck'); // Test the exact error message - expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/); - expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor')); + expect(drinkOctopus).toThrow(/^yuck, octopus flavor$/); + expect(drinkOctopus).toThrow(new Error('yuck, octopus flavor')); // Test that we get a DisgustingFlavorError - expect(drinkOctopus).toThrowError(DisgustingFlavorError); + expect(drinkOctopus).toThrow(DisgustingFlavorError); }); ``` diff --git a/website/versioned_docs/version-29.0/GlobalAPI.md b/website/versioned_docs/version-29.0/GlobalAPI.md index 775d40d11d9c..6bcbacd0b68b 100644 --- a/website/versioned_docs/version-29.0/GlobalAPI.md +++ b/website/versioned_docs/version-29.0/GlobalAPI.md @@ -212,11 +212,11 @@ const binaryStringToNumber = binString => { describe('binaryStringToNumber', () => { describe('given an invalid binary string', () => { test('composed of non-numbers throws CustomError', () => { - expect(() => binaryStringToNumber('abc')).toThrowError(CustomError); + expect(() => binaryStringToNumber('abc')).toThrow(CustomError); }); test('with extra whitespace throws CustomError', () => { - expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError); + expect(() => binaryStringToNumber(' 100')).toThrow(CustomError); }); }); diff --git a/website/versioned_docs/version-29.0/MockFunctionAPI.md b/website/versioned_docs/version-29.0/MockFunctionAPI.md index 411d8111869d..bf5007aad60e 100644 --- a/website/versioned_docs/version-29.0/MockFunctionAPI.md +++ b/website/versioned_docs/version-29.0/MockFunctionAPI.md @@ -511,8 +511,8 @@ test('calculate calls add', () => { // requiring `add`. calculate(mockAdd, 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` diff --git a/website/versioned_docs/version-29.1/ExpectAPI.md b/website/versioned_docs/version-29.1/ExpectAPI.md index 8ecb0152a4da..54d2d16a9d48 100644 --- a/website/versioned_docs/version-29.1/ExpectAPI.md +++ b/website/versioned_docs/version-29.1/ExpectAPI.md @@ -503,7 +503,7 @@ it('transitions as expected', () => { test('map calls its argument with a non-null argument', () => { const mock = jest.fn(); [1].map(x => mock(x)); - expect(mock).toBeCalledWith(expect.anything()); + expect(mock).toHaveBeenCalledWith(expect.anything()); }); ``` @@ -520,7 +520,7 @@ function getCat(fn) { test('randocall calls its callback with a class instance', () => { const mock = jest.fn(); getCat(mock); - expect(mock).toBeCalledWith(expect.any(Cat)); + expect(mock).toHaveBeenCalledWith(expect.any(Cat)); }); function randocall(fn) { @@ -530,7 +530,7 @@ function randocall(fn) { test('randocall calls its callback with a number', () => { const mock = jest.fn(); randocall(mock); - expect(mock).toBeCalledWith(expect.any(Number)); + expect(mock).toHaveBeenCalledWith(expect.any(Number)); }); ``` @@ -709,7 +709,7 @@ For example, let's say that we expect an `onPress` function to be called with an test('onPress gets called with the right thing', () => { const onPress = jest.fn(); simulatePresses(onPress); - expect(onPress).toBeCalledWith( + expect(onPress).toHaveBeenCalledWith( expect.objectContaining({ x: expect.any(Number), y: expect.any(Number), @@ -1548,15 +1548,15 @@ test('throws on octopus', () => { } // Test that the error message says "yuck" somewhere: these are equivalent - expect(drinkOctopus).toThrowError(/yuck/); - expect(drinkOctopus).toThrowError('yuck'); + expect(drinkOctopus).toThrow(/yuck/); + expect(drinkOctopus).toThrow('yuck'); // Test the exact error message - expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/); - expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor')); + expect(drinkOctopus).toThrow(/^yuck, octopus flavor$/); + expect(drinkOctopus).toThrow(new Error('yuck, octopus flavor')); // Test that we get a DisgustingFlavorError - expect(drinkOctopus).toThrowError(DisgustingFlavorError); + expect(drinkOctopus).toThrow(DisgustingFlavorError); }); ``` diff --git a/website/versioned_docs/version-29.1/GlobalAPI.md b/website/versioned_docs/version-29.1/GlobalAPI.md index 775d40d11d9c..6bcbacd0b68b 100644 --- a/website/versioned_docs/version-29.1/GlobalAPI.md +++ b/website/versioned_docs/version-29.1/GlobalAPI.md @@ -212,11 +212,11 @@ const binaryStringToNumber = binString => { describe('binaryStringToNumber', () => { describe('given an invalid binary string', () => { test('composed of non-numbers throws CustomError', () => { - expect(() => binaryStringToNumber('abc')).toThrowError(CustomError); + expect(() => binaryStringToNumber('abc')).toThrow(CustomError); }); test('with extra whitespace throws CustomError', () => { - expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError); + expect(() => binaryStringToNumber(' 100')).toThrow(CustomError); }); }); diff --git a/website/versioned_docs/version-29.1/MockFunctionAPI.md b/website/versioned_docs/version-29.1/MockFunctionAPI.md index 43a95bb3192e..fef7d983aec6 100644 --- a/website/versioned_docs/version-29.1/MockFunctionAPI.md +++ b/website/versioned_docs/version-29.1/MockFunctionAPI.md @@ -548,8 +548,8 @@ test('calculate calls add', () => { // requiring `add`. calculate(mockAdd, 1, 2); - expect(mockAdd).toBeCalledTimes(1); - expect(mockAdd).toBeCalledWith(1, 2); + expect(mockAdd).toHaveBeenCalledTimes(1); + expect(mockAdd).toHaveBeenCalledWith(1, 2); }); ``` From 2949e737a33b56be537e17de629e93e8bde37ab6 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 3 Oct 2022 17:27:17 +0300 Subject: [PATCH 2/4] snaps --- e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap | 4 ++-- e2e/__tests__/failureDetailsProperty.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap index 20aad34dd9ef..c7eb02d6cfe1 100644 --- a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap +++ b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap @@ -41,7 +41,7 @@ exports[`moduleNameMapper wrong array configuration 1`] = ` 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:891:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:896:17) at Object.require (index.js:10:1) at Object.require (__tests__/index.js:10:20)" `; @@ -71,7 +71,7 @@ exports[`moduleNameMapper wrong configuration 1`] = ` 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:891:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:896:17) at Object.require (index.js:10:1) at Object.require (__tests__/index.js:10:20)" `; diff --git a/e2e/__tests__/failureDetailsProperty.test.ts b/e2e/__tests__/failureDetailsProperty.test.ts index 18dd488864e0..2c3997d1c456 100644 --- a/e2e/__tests__/failureDetailsProperty.test.ts +++ b/e2e/__tests__/failureDetailsProperty.test.ts @@ -245,7 +245,7 @@ test('that the failureDetails property is set', () => { ], Array [ Object { - "message": "expect(received).rejects.toThrowError() + "message": "expect(received).rejects.toThrow() Received promise resolved instead of rejected Resolved to value: 1", From 4b3bc9547ce247b929569177141630af1f54b445 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 3 Oct 2022 17:36:33 +0300 Subject: [PATCH 3/4] fix snap --- e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap index c7eb02d6cfe1..20aad34dd9ef 100644 --- a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap +++ b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap @@ -41,7 +41,7 @@ exports[`moduleNameMapper wrong array configuration 1`] = ` 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:896:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:891:17) at Object.require (index.js:10:1) at Object.require (__tests__/index.js:10:20)" `; @@ -71,7 +71,7 @@ exports[`moduleNameMapper wrong configuration 1`] = ` 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:896:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:891:17) at Object.require (index.js:10:1) at Object.require (__tests__/index.js:10:20)" `; From 7d830d9a53c0ae1790ff24617e7bdefa3b936234 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 3 Oct 2022 17:47:41 +0300 Subject: [PATCH 4/4] jasmine snap --- e2e/__tests__/failureDetailsProperty.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/__tests__/failureDetailsProperty.test.ts b/e2e/__tests__/failureDetailsProperty.test.ts index 2c3997d1c456..9b53b8d70668 100644 --- a/e2e/__tests__/failureDetailsProperty.test.ts +++ b/e2e/__tests__/failureDetailsProperty.test.ts @@ -160,19 +160,19 @@ test('that the failureDetails property is set', () => { Object { "actual": "", "error": Object { - "message": "expect(received).rejects.toThrowError() + "message": "expect(received).rejects.toThrow() Received promise resolved instead of rejected Resolved to value: 1", }, "expected": "", "matcherName": "", - "message": "Error: expect(received).rejects.toThrowError() + "message": "Error: expect(received).rejects.toThrow() Received promise resolved instead of rejected Resolved to value: 1", "passed": false, - "stack": "Error: expect(received).rejects.toThrowError() + "stack": "Error: expect(received).rejects.toThrow() Received promise resolved instead of rejected Resolved to value: 1