diff --git a/api/src/routes/user.test.ts b/api/src/routes/user.test.ts index 75bc78a8b03..d691ef61f73 100644 --- a/api/src/routes/user.test.ts +++ b/api/src/routes/user.test.ts @@ -659,8 +659,8 @@ describe('userRoutes', () => { 'Luke, I am your father' }); - expect(sendEmailSpy).toBeCalledTimes(1); - expect(sendEmailSpy).toBeCalledWith( + expect(sendEmailSpy).toHaveBeenCalledTimes(1); + expect(sendEmailSpy).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining( 'Report Details:\n\nLuke, I am your father' @@ -680,8 +680,8 @@ describe('userRoutes', () => { reportDescription: 'Luke, I am your father' }); - expect(sendEmailSpy).toBeCalledTimes(1); - expect(sendEmailSpy).toBeCalledWith({ + expect(sendEmailSpy).toHaveBeenCalledTimes(1); + expect(sendEmailSpy).toHaveBeenCalledWith({ from: 'team@freecodecamp.org', to: 'support@freecodecamp.org', cc: 'foo@bar.com', diff --git a/client/src/templates/Challenges/utils/worker-executor.test.js b/client/src/templates/Challenges/utils/worker-executor.test.js index b816bdbdf6c..f4cffd38798 100644 --- a/client/src/templates/Challenges/utils/worker-executor.test.js +++ b/client/src/templates/Challenges/utils/worker-executor.test.js @@ -44,14 +44,14 @@ it('Worker executor should successfully execute one task', async () => { await expect(task.done).resolves.toBe('test processed'); - expect(handler).toBeCalledTimes(1); - expect(handler).toBeCalledWith('test processed'); + expect(handler).toHaveBeenCalledTimes(1); + expect(handler).toHaveBeenCalledWith('test processed'); - expect(errorHandler).not.toBeCalled(); - expect(terminateHandler).not.toBeCalled(); + expect(errorHandler).not.toHaveBeenCalled(); + expect(terminateHandler).not.toHaveBeenCalled(); - expect(global.Worker).toBeCalledTimes(1); - expect(global.Worker).toBeCalledWith('/js/test.js'); + expect(global.Worker).toHaveBeenCalledTimes(1); + expect(global.Worker).toHaveBeenCalledWith('/js/test.js'); }); it('Worker executor should successfully execute two tasks in parallel', async () => { @@ -76,16 +76,16 @@ it('Worker executor should successfully execute two tasks in parallel', async () 'test2 processed' ]); - expect(handler1).toBeCalledTimes(1); - expect(handler1).toBeCalledWith('test1 processed'); - expect(errorHandler1).not.toBeCalled(); + expect(handler1).toHaveBeenCalledTimes(1); + expect(handler1).toHaveBeenCalledWith('test1 processed'); + expect(errorHandler1).not.toHaveBeenCalled(); - expect(handler2).toBeCalledTimes(1); - expect(handler2).toBeCalledWith('test2 processed'); - expect(errorHandler2).not.toBeCalled(); - expect(terminateHandler).not.toBeCalled(); + expect(handler2).toHaveBeenCalledTimes(1); + expect(handler2).toHaveBeenCalledWith('test2 processed'); + expect(errorHandler2).not.toHaveBeenCalled(); + expect(terminateHandler).not.toHaveBeenCalled(); - expect(global.Worker).toBeCalledTimes(2); + expect(global.Worker).toHaveBeenCalledTimes(2); }); it('Worker executor should successfully execute 3 tasks in parallel and use two workers', async () => { @@ -99,7 +99,7 @@ it('Worker executor should successfully execute 3 tasks in parallel and use two Promise.all([task1.done, task2.done, task3.done]) ).resolves.toEqual(['test1 processed', 'test2 processed', 'test3 processed']); - expect(global.Worker).toBeCalledTimes(2); + expect(global.Worker).toHaveBeenCalledTimes(2); }); it('Worker executor should successfully execute 3 tasks, use 3 workers and terminate each worker', async () => { @@ -114,8 +114,8 @@ it('Worker executor should successfully execute 3 tasks, use 3 workers and termi Promise.all([task1.done, task2.done, task3.done]) ).resolves.toEqual(['test1 processed', 'test2 processed', 'test3 processed']); - expect(terminateHandler).toBeCalledTimes(3); - expect(global.Worker).toBeCalledTimes(3); + expect(terminateHandler).toHaveBeenCalledTimes(3); + expect(global.Worker).toHaveBeenCalledTimes(3); }); it('Worker executor should successfully execute 3 tasks in parallel and use 3 workers', async () => { @@ -129,7 +129,7 @@ it('Worker executor should successfully execute 3 tasks in parallel and use 3 wo Promise.all([task1.done, task2.done, task3.done]) ).resolves.toEqual(['test1 processed', 'test2 processed', 'test3 processed']); - expect(global.Worker).toBeCalledTimes(3); + expect(global.Worker).toHaveBeenCalledTimes(3); }); it('Worker executor should successfully execute 3 tasks and use 1 worker', async () => { @@ -143,7 +143,7 @@ it('Worker executor should successfully execute 3 tasks and use 1 worker', async Promise.all([task1.done, task2.done, task3.done]) ).resolves.toEqual(['test1 processed', 'test2 processed', 'test3 processed']); - expect(global.Worker).toBeCalledTimes(1); + expect(global.Worker).toHaveBeenCalledTimes(1); }); it('Worker executor should reject task', async () => { @@ -160,8 +160,8 @@ it('Worker executor should reject task', async () => { task.on('error', errorHandler); await expect(task.done).rejects.toBe(error.message); - expect(errorHandler).toBeCalledTimes(1); - expect(errorHandler).toBeCalledWith(error); + expect(errorHandler).toHaveBeenCalledTimes(1); + expect(errorHandler).toHaveBeenCalledWith(error); }); it('Worker executor should emit LOG events', async () => { @@ -193,11 +193,11 @@ it('Worker executor should emit LOG events', async () => { await expect(task.done).resolves.toBe('test processed'); - expect(handler).toBeCalledTimes(1); - expect(handler).toBeCalledWith('test processed'); - expect(errorHandler).not.toBeCalled(); + expect(handler).toHaveBeenCalledTimes(1); + expect(handler).toHaveBeenCalledWith('test processed'); + expect(errorHandler).not.toHaveBeenCalled(); - expect(logHandler).toBeCalledTimes(3); + expect(logHandler).toHaveBeenCalledTimes(3); for (let i = 0; i < 3; i++) { expect(logHandler.mock.calls[i][0]).toBe(i); } @@ -216,10 +216,10 @@ it('Worker executor should reject task on timeout', async () => { task.on('error', errorHandler); await expect(task.done).rejects.toBe('timeout'); - expect(errorHandler).toBeCalledTimes(1); + expect(errorHandler).toHaveBeenCalledTimes(1); expect(errorHandler.mock.calls[0][0]).toEqual({ message: 'timeout' }); - expect(terminateHandler).toBeCalledTimes(1); + expect(terminateHandler).toHaveBeenCalledTimes(1); }); it('Worker executor should get worker from specified location', async () => { @@ -231,8 +231,8 @@ it('Worker executor should get worker from specified location', async () => { const task = testWorker.execute('test'); await expect(task.done).resolves.toBe('test processed'); - expect(global.Worker).toBeCalledTimes(1); - expect(global.Worker).toBeCalledWith('/other/location/test.js'); + expect(global.Worker).toHaveBeenCalledTimes(1); + expect(global.Worker).toHaveBeenCalledWith('/other/location/test.js'); }); it('Task should only emit handler once', () => { @@ -244,5 +244,5 @@ it('Task should only emit handler once', () => { task.emit('testOnce', handler); task.emit('testOnce', handler); - expect(handler).toBeCalledTimes(1); + expect(handler).toHaveBeenCalledTimes(1); }); diff --git a/tools/ui-components/src/button/button.test.tsx b/tools/ui-components/src/button/button.test.tsx index 178cea8fc50..7cc90d755ad 100644 --- a/tools/ui-components/src/button/button.test.tsx +++ b/tools/ui-components/src/button/button.test.tsx @@ -69,7 +69,7 @@ describe('