diff --git a/packages/coinjoin/tests/client/CoinjoinRound.test.ts b/packages/coinjoin/tests/client/CoinjoinRound.test.ts index 5ef662dab2..937dfda4b2 100644 --- a/packages/coinjoin/tests/client/CoinjoinRound.test.ts +++ b/packages/coinjoin/tests/client/CoinjoinRound.test.ts @@ -92,8 +92,10 @@ describe(`CoinjoinRound`, () => { await round.process([]); - expect(logger.error).toBeCalledTimes(1); - expect(logger.error).toBeCalledWith(expect.stringMatching(/Missing affiliate request/)); + expect(logger.error).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledWith( + expect.stringMatching(/Missing affiliate request/), + ); }); it('catch failed Round', async () => { @@ -125,8 +127,10 @@ describe(`CoinjoinRound`, () => { // process phase (will throw error Missing credentials to join) await round.process([]); - expect(logger.error).toBeCalledTimes(1); - expect(logger.error).toBeCalledWith(expect.stringMatching(/Output registration failed/)); + expect(logger.error).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledWith( + expect.stringMatching(/Output registration failed/), + ); }); it('end Round if any input-registration fails and there is only one account', async () => { @@ -222,7 +226,7 @@ describe(`CoinjoinRound`, () => { // input-registration is now set with delay ~0.8 sec. // we want to change phase earlier await new Promise(resolve => setTimeout(resolve, 500)); - expect(registrationSpy).toBeCalledTimes(0); // no registrations yet + expect(registrationSpy).toHaveBeenCalledTimes(0); // no registrations yet // change Round phase before input-registration was called await round.onPhaseChange({ ...DEFAULT_ROUND, Phase: 1 }); @@ -235,15 +239,15 @@ describe(`CoinjoinRound`, () => { expect(input.registrationData).not.toBeUndefined(); expect(input.getConfirmationInterval).not.toBeUndefined(); }); - expect(registrationSpy).toBeCalledTimes(2); // two registrations - expect(confirmationSpy).toBeCalledTimes(0); // no confirmations yet + expect(registrationSpy).toHaveBeenCalledTimes(2); // two registrations + expect(confirmationSpy).toHaveBeenCalledTimes(0); // no confirmations yet await round.process([]); round.inputs.forEach(input => { expect(input.error).toBeUndefined(); expect(input.confirmationData).not.toBeUndefined(); }); - expect(confirmationSpy).toBeCalledTimes(2); // two confirmations + expect(confirmationSpy).toHaveBeenCalledTimes(2); // two confirmations delayMock.mockRestore(); constantsMock.mockRestore(); @@ -339,7 +343,7 @@ describe(`CoinjoinRound`, () => { expect(round.inputs.length).toBe(0); // no valid inputs, requests aborted expect(round.failed.length).toBe(0); // no errored inputs, inputs with errors in inputRegistration are not passed further - expect(spy).toBeCalledTimes(2); // two registrations called + expect(spy).toHaveBeenCalledTimes(2); // two registrations called }); it('unregisterAccount not in critical phase', () => { @@ -359,11 +363,11 @@ describe(`CoinjoinRound`, () => { round.on('changed', spyChanged); round.unregisterAccount('account-A'); - expect(spyEnded).toBeCalledTimes(0); // not called because there is also account-B input in round + expect(spyEnded).toHaveBeenCalledTimes(0); // not called because there is also account-B input in round round.unregisterAccount('account-B'); - expect(spyEnded).toBeCalledTimes(1); - expect(spyChanged).toBeCalledTimes(1); + expect(spyEnded).toHaveBeenCalledTimes(1); + expect(spyChanged).toHaveBeenCalledTimes(1); }); it('unregisterAccount in critical phase', () => { @@ -384,8 +388,8 @@ describe(`CoinjoinRound`, () => { round.on('changed', spyChanged); round.unregisterAccount('account-A'); - expect(spyEnded).toBeCalledTimes(1); // called immediately event if there is account-B input in round - expect(spyChanged).toBeCalledTimes(1); + expect(spyEnded).toHaveBeenCalledTimes(1); // called immediately event if there is account-B input in round + expect(spyChanged).toHaveBeenCalledTimes(1); }); it('unregisterAccount when round is locked', async () => { @@ -415,8 +419,8 @@ describe(`CoinjoinRound`, () => { // process but not wait for the result round.process([]).then(() => { - expect(spyEnded).toBeCalledTimes(1); - expect(spyChanged).toBeCalledTimes(1); + expect(spyEnded).toHaveBeenCalledTimes(1); + expect(spyChanged).toHaveBeenCalledTimes(1); }); // we want to unregister account before input-registration response diff --git a/packages/coinjoin/tests/client/connectionConfirmation.test.ts b/packages/coinjoin/tests/client/connectionConfirmation.test.ts index 28362afbf2..727ed6bd52 100644 --- a/packages/coinjoin/tests/client/connectionConfirmation.test.ts +++ b/packages/coinjoin/tests/client/connectionConfirmation.test.ts @@ -89,7 +89,7 @@ describe('connectionConfirmation', () => { }); // confirmation request sent only for second input - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenLastCalledWith('01B1-01b1'); }); @@ -134,7 +134,7 @@ describe('connectionConfirmation', () => { ); // confirmation request called twice for each input - expect(spy).toBeCalledTimes(4); + expect(spy).toHaveBeenCalledTimes(4); response.inputs.forEach(input => { // inputs are not confirmed, deadline reached (~2.5 sec: phaseDeadline + connectionConfirmationTimeout) expect(input.error?.message).toMatch(/Aborted by deadline/); @@ -180,7 +180,7 @@ describe('connectionConfirmation', () => { server?.requestOptions, ).promise; - expect(spy).toBeCalledTimes(4); + expect(spy).toHaveBeenCalledTimes(4); timestamps .map((a, i) => { diff --git a/packages/coinjoin/tests/client/coordinatorRequest.test.ts b/packages/coinjoin/tests/client/coordinatorRequest.test.ts index 4fb60d8cac..5c6041f8d4 100644 --- a/packages/coinjoin/tests/client/coordinatorRequest.test.ts +++ b/packages/coinjoin/tests/client/coordinatorRequest.test.ts @@ -90,7 +90,7 @@ describe('http', () => { ).rejects.toThrow('Forbidden'); // 3 attempts with 3 identities - expect(requestListener).toBeCalledTimes(3); + expect(requestListener).toHaveBeenCalledTimes(3); expect(identities[0]).not.toEqual(identities[1]); expect(identities[1]).not.toEqual(identities[2]); }); @@ -115,7 +115,7 @@ describe('http', () => { { baseUrl, deadline: Date.now() + 3000, identity: 'abcd' }, ); - expect(spy).toBeCalledTimes(2); + expect(spy).toHaveBeenCalledTimes(2); expect(resp.RoundStates.length).toEqual(1); }); diff --git a/packages/coinjoin/tests/client/endedRound.test.ts b/packages/coinjoin/tests/client/endedRound.test.ts index 29aaacc5f9..1bcd203ffc 100644 --- a/packages/coinjoin/tests/client/endedRound.test.ts +++ b/packages/coinjoin/tests/client/endedRound.test.ts @@ -50,8 +50,10 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(1); - expect(logger.error).toBeCalledWith(expect.stringMatching(/Missing confirmed inputs/)); + expect(logger.error).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledWith( + expect.stringMatching(/Missing confirmed inputs/), + ); expect(round.prison.inmates.length).toEqual(1); }); @@ -81,8 +83,8 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(1); - expect(logger.error).toBeCalledWith(expect.stringMatching(/Missing outputs/)); + expect(logger.error).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledWith(expect.stringMatching(/Missing outputs/)); expect(round.prison.inmates.length).toEqual(1); }); @@ -121,8 +123,10 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(1); - expect(logger.error).toBeCalledWith(expect.stringMatching(/Missing affiliate request/)); + expect(logger.error).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledWith( + expect.stringMatching(/Missing affiliate request/), + ); expect(round.prison.inmates.length).toEqual(2); // input + output are detained }); @@ -162,8 +166,8 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(1); - expect(logger.error).toBeCalledWith(expect.stringMatching(/Missing signed inputs/)); + expect(logger.error).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledWith(expect.stringMatching(/Missing signed inputs/)); expect(round.prison.inmates.length).toEqual(2); // input + output are detained }); @@ -203,8 +207,10 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(1); - expect(logger.error).toBeCalledWith(expect.stringMatching(/This should never happen/)); + expect(logger.error).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledWith( + expect.stringMatching(/This should never happen/), + ); expect(round.prison.inmates.length).toEqual(2); // input + output are detained }); @@ -245,7 +251,7 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(0); + expect(logger.error).toHaveBeenCalledTimes(0); expect(round.prison.inmates.length).toEqual(0); }); @@ -286,7 +292,7 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(0); + expect(logger.error).toHaveBeenCalledTimes(0); expect(round.prison.inmates.length).toEqual(2); // input and address (output) detained }); @@ -322,7 +328,7 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(0); + expect(logger.error).toHaveBeenCalledTimes(0); expect(round.prison.inmates.length).toEqual(0); // input released from detention }); @@ -358,7 +364,7 @@ describe('ended', () => { ended(round, options); - expect(logger.error).toBeCalledTimes(0); + expect(logger.error).toHaveBeenCalledTimes(0); expect(round.prison.inmates.length).toEqual(2); // input and output detained forever }); }); diff --git a/packages/coinjoin/tests/client/inputRegistration.test.ts b/packages/coinjoin/tests/client/inputRegistration.test.ts index e554a53540..ed6e4eaeb8 100644 --- a/packages/coinjoin/tests/client/inputRegistration.test.ts +++ b/packages/coinjoin/tests/client/inputRegistration.test.ts @@ -279,7 +279,7 @@ describe('inputRegistration', () => { await Promise.all(response.inputs.map(input => input.getConfirmationInterval()?.promise)); - expect(spy).toBeCalledTimes(3); // connection-confirmation was called 2 times: 10 sec phase deadline divided by 2 * 2.5 sec connectionConfirmationTimeout + expect(spy).toHaveBeenCalledTimes(3); // connection-confirmation was called 2 times: 10 sec phase deadline divided by 2 * 2.5 sec connectionConfirmationTimeout }, 10000); it('success. connection-confirmation returns realCredentials (coordinator is already in phase 1)', async () => { @@ -304,7 +304,7 @@ describe('inputRegistration', () => { await Promise.all(response.inputs.map(input => input.getConfirmationInterval()?.promise)); - expect(spy).toBeCalledTimes(1); // connection-confirmation was called 1 time and responded with real realCredentials (default response of MockedServer) + expect(spy).toHaveBeenCalledTimes(1); // connection-confirmation was called 1 time and responded with real realCredentials (default response of MockedServer) expect(response.inputs[0].confirmationData).toMatchObject({ RealAmountCredentials: expect.any(Object), }); diff --git a/packages/coinjoin/tests/client/outputDecomposition.test.ts b/packages/coinjoin/tests/client/outputDecomposition.test.ts index b8a87201d0..e98ff1a3eb 100644 --- a/packages/coinjoin/tests/client/outputDecomposition.test.ts +++ b/packages/coinjoin/tests/client/outputDecomposition.test.ts @@ -88,7 +88,7 @@ describe('outputRegistration', () => { expect(r).toMatchObject(f.result[i]); }); expect(availableVsize).toEqual(f.availableVsize); - expect(spy).toBeCalledTimes(f.credentialIssuanceCalls); + expect(spy).toHaveBeenCalledTimes(f.credentialIssuanceCalls); }); }); }); diff --git a/packages/coinjoin/tests/client/selectRound.test.ts b/packages/coinjoin/tests/client/selectRound.test.ts index 0378cd3188..91b15aaee9 100644 --- a/packages/coinjoin/tests/client/selectRound.test.ts +++ b/packages/coinjoin/tests/client/selectRound.test.ts @@ -223,7 +223,7 @@ describe('selectRound', () => { options: server?.requestOptions, }); - expect(spy).toBeCalledTimes(6); + expect(spy).toHaveBeenCalledTimes(6); expect(result).toBeUndefined(); }); @@ -278,7 +278,7 @@ describe('selectRound', () => { options: server?.requestOptions, }); - expect(spy).toBeCalledTimes(1); // middleware was called once for account3 + expect(spy).toHaveBeenCalledTimes(1); // middleware was called once for account3 expect(result).toBeUndefined(); }); @@ -313,7 +313,7 @@ describe('selectRound', () => { options: server?.requestOptions, }); - expect(spy).toBeCalledTimes(1); // middleware was called once + expect(spy).toHaveBeenCalledTimes(1); // middleware was called once expect(result).toBeUndefined(); }); @@ -347,7 +347,7 @@ describe('selectRound', () => { options: server?.requestOptions, }); - expect(spy).toBeCalledTimes(1); // middleware was called once + expect(spy).toHaveBeenCalledTimes(1); // middleware was called once expect(result).toBeUndefined(); }); @@ -495,7 +495,7 @@ describe('selectRound', () => { runningAffiliateServer: true, }); - expect(spy).toBeCalledTimes(9); + expect(spy).toHaveBeenCalledTimes(9); ['AA', 'AB', 'AC', 'CA'].forEach((outpoint, index) => { expect(result!.inputs[index].outpoint).toEqual(outpoint); @@ -553,7 +553,7 @@ describe('selectRound', () => { runningAffiliateServer: true, }); - expect(spy).toBeCalledTimes(0); // middleware was not called, detained inputs were used + expect(spy).toHaveBeenCalledTimes(0); // middleware was not called, detained inputs were used expect(result?.inputs.length).toBe(2); expect(result).toMatchObject({ id: '02', diff --git a/packages/coinjoin/tests/client/transactionSigning.test.ts b/packages/coinjoin/tests/client/transactionSigning.test.ts index b0b1b4e3b5..2c446c637f 100644 --- a/packages/coinjoin/tests/client/transactionSigning.test.ts +++ b/packages/coinjoin/tests/client/transactionSigning.test.ts @@ -342,7 +342,7 @@ describe('transactionSigning', () => { server?.requestOptions, ); - expect(spy).toBeCalledTimes(4); // called 4 times because witnessIndex 1 was repeated + expect(spy).toHaveBeenCalledTimes(4); // called 4 times because witnessIndex 1 was repeated response.inputs.forEach(input => { expect(input.error).toBe(undefined); diff --git a/packages/connect/e2e/tests/device/authorizeCoinjoin.test.ts b/packages/connect/e2e/tests/device/authorizeCoinjoin.test.ts index c8e8bb5fd8..79bac854a0 100644 --- a/packages/connect/e2e/tests/device/authorizeCoinjoin.test.ts +++ b/packages/connect/e2e/tests/device/authorizeCoinjoin.test.ts @@ -239,7 +239,7 @@ describe('TrezorConnect.authorizeCoinjoin', () => { useEmptyPassphrase: true, }); - expect(spy).toBeCalledTimes(1 * confirmationScreensCount); + expect(spy).toHaveBeenCalledTimes(1 * confirmationScreensCount); // re-authorize await TrezorConnect.authorizeCoinjoin({ @@ -249,7 +249,7 @@ describe('TrezorConnect.authorizeCoinjoin', () => { preauthorized: true, }); - expect(spy).toBeCalledTimes(1 * confirmationScreensCount); // no more button requests + expect(spy).toHaveBeenCalledTimes(1 * confirmationScreensCount); // no more button requests // authorize passphrase wallet await TrezorConnect.authorizeCoinjoin({ @@ -257,7 +257,7 @@ describe('TrezorConnect.authorizeCoinjoin', () => { device: { instance: 1, state: walletA.payload.state }, }); - expect(spy).toBeCalledTimes(2 * confirmationScreensCount); + expect(spy).toHaveBeenCalledTimes(2 * confirmationScreensCount); // re-authorize passphrase wallet await TrezorConnect.authorizeCoinjoin({ @@ -281,7 +281,7 @@ describe('TrezorConnect.authorizeCoinjoin', () => { preauthorized: true, }); - expect(spy).toBeCalledTimes(2 * confirmationScreensCount); // no more button requests + expect(spy).toHaveBeenCalledTimes(2 * confirmationScreensCount); // no more button requests // disable passphrase for future tests await TrezorConnect.applySettings({ use_passphrase: false }); diff --git a/packages/ipc-proxy/src/__tests__/proxy.test.ts b/packages/ipc-proxy/src/__tests__/proxy.test.ts index aa241bb24e..6a1800dabc 100644 --- a/packages/ipc-proxy/src/__tests__/proxy.test.ts +++ b/packages/ipc-proxy/src/__tests__/proxy.test.ts @@ -71,28 +71,28 @@ describe('proxy', () => { proxy.on('test-api-event', spy1); // NOTE: emit fn is async in proxy await proxy.emit('test-api-event', 'ActualResponse-arg-1', 'ActualResponse-arg-2'); - expect(spy1).toBeCalledWith('ActualResponse-arg-1', 'ActualResponse-arg-2'); + expect(spy1).toHaveBeenCalledWith('ActualResponse-arg-1', 'ActualResponse-arg-2'); const spy2 = jest.fn(); proxy.on('test-api-event', spy2); await proxy.emit('test-api-event'); - expect(spy1).toBeCalledTimes(2); - expect(spy2).toBeCalledTimes(1); + expect(spy1).toHaveBeenCalledTimes(2); + expect(spy2).toHaveBeenCalledTimes(1); proxy.off('test-api-event', spy1); await proxy.emit('test-api-event'); - expect(spy1).toBeCalledTimes(2); // listener was removed, number of calls is still the same - expect(spy2).toBeCalledTimes(2); + expect(spy1).toHaveBeenCalledTimes(2); // listener was removed, number of calls is still the same + expect(spy2).toHaveBeenCalledTimes(2); const spy3 = jest.fn(); proxy.on('test-api-event', spy3); proxy.removeAllListeners('test-api-event'); await proxy.emit('test-api-event'); // all listener removed, number of calls is still the same - expect(spy1).toBeCalledTimes(2); - expect(spy2).toBeCalledTimes(2); - expect(spy3).toBeCalledTimes(0); + expect(spy1).toHaveBeenCalledTimes(2); + expect(spy2).toHaveBeenCalledTimes(2); + expect(spy3).toHaveBeenCalledTimes(0); }); it('proper proxy event removing', async () => { @@ -107,23 +107,23 @@ describe('proxy', () => { proxy.on('test-api-event', spyFoo); await proxy.emit('test-api-event'); - expect(spyFoo).toBeCalledTimes(1); - expect(spyBar).toBeCalledTimes(0); + expect(spyFoo).toHaveBeenCalledTimes(1); + expect(spyBar).toHaveBeenCalledTimes(0); proxy.on('test-api-event', spyBar); await proxy.emit('test-api-event'); - expect(spyFoo).toBeCalledTimes(2); - expect(spyBar).toBeCalledTimes(1); + expect(spyFoo).toHaveBeenCalledTimes(2); + expect(spyBar).toHaveBeenCalledTimes(1); proxy.off('test-api-event', spyBar); await proxy.emit('test-api-event'); - expect(spyFoo).toBeCalledTimes(3); - expect(spyBar).toBeCalledTimes(1); + expect(spyFoo).toHaveBeenCalledTimes(3); + expect(spyBar).toHaveBeenCalledTimes(1); proxy.off('test-api-event', spyFoo); await proxy.emit('test-api-event'); - expect(spyFoo).toBeCalledTimes(3); - expect(spyBar).toBeCalledTimes(1); + expect(spyFoo).toHaveBeenCalledTimes(3); + expect(spyBar).toHaveBeenCalledTimes(1); }); it('multiple proxy instances', async () => { @@ -137,13 +137,13 @@ describe('proxy', () => { proxy2.on('foo', spy2); await proxy1.emit('foo'); - expect(spy1).toBeCalledTimes(1); - expect(spy2).toBeCalledTimes(0); + expect(spy1).toHaveBeenCalledTimes(1); + expect(spy2).toHaveBeenCalledTimes(0); await proxy2.emit('foo'); await proxy2.emit('foo'); - expect(spy1).toBeCalledTimes(1); - expect(spy2).toBeCalledTimes(2); + expect(spy1).toHaveBeenCalledTimes(1); + expect(spy2).toHaveBeenCalledTimes(2); }); it('invalid channel', async () => { diff --git a/packages/suite-desktop-api/src/__tests__/api.test.ts b/packages/suite-desktop-api/src/__tests__/api.test.ts index 93d70a1567..1fe8f56bb9 100644 --- a/packages/suite-desktop-api/src/__tests__/api.test.ts +++ b/packages/suite-desktop-api/src/__tests__/api.test.ts @@ -36,7 +36,7 @@ describe('DesktopApi', () => { ipcRenderer.emit('oauth/response', new Event('ipc'), {}); ipcRenderer.emit('oauth/response', new Event('ipc'), {}); - expect(spy).toBeCalledTimes(1); // Only one event is processed + expect(spy).toHaveBeenCalledTimes(1); // Only one event is processed }); it('DesktopApi.on invalid channel', () => { @@ -47,7 +47,7 @@ describe('DesktopApi', () => { api.once('invalid-2', spy); ipcRenderer.emit('invalid-1', new Event('ipc'), true); ipcRenderer.emit('invalid-2', new Event('ipc'), true); - expect(spy).toBeCalledTimes(0); + expect(spy).toHaveBeenCalledTimes(0); }); }); @@ -55,7 +55,7 @@ describe('DesktopApi', () => { it('DesktopApi.appRestart', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.appRestart(); - expect(spy).toBeCalledWith('app/restart'); + expect(spy).toHaveBeenCalledWith('app/restart'); // @ts-expect-error no expected params api.appRestart(true); @@ -64,7 +64,7 @@ describe('DesktopApi', () => { it('DesktopApi.appFocus', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.appFocus(); - expect(spy).toBeCalledWith('app/focus'); + expect(spy).toHaveBeenCalledWith('app/focus'); // @ts-expect-error no expected params api.appFocus(true); @@ -73,19 +73,19 @@ describe('DesktopApi', () => { it('DesktopApi.checkForUpdates', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.checkForUpdates(); - expect(spy).toBeCalledWith('update/check', undefined); + expect(spy).toHaveBeenCalledWith('update/check', undefined); api.checkForUpdates(true); - expect(spy).toBeCalledWith('update/check', true); + expect(spy).toHaveBeenCalledWith('update/check', true); // @ts-expect-error invalid param api.checkForUpdates('string'); - expect(spy).toBeCalledTimes(2); // invalid param not processed + expect(spy).toHaveBeenCalledTimes(2); // invalid param not processed }); it('DesktopApi.downloadUpdate', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.downloadUpdate(); - expect(spy).toBeCalledWith('update/download'); + expect(spy).toHaveBeenCalledWith('update/download'); // @ts-expect-error no expected params api.downloadUpdate(true); @@ -94,7 +94,7 @@ describe('DesktopApi', () => { it('DesktopApi.installUpdate', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.installUpdate(); - expect(spy).toBeCalledWith('update/install'); + expect(spy).toHaveBeenCalledWith('update/install'); // @ts-expect-error no expected params api.installUpdate(true); @@ -103,7 +103,7 @@ describe('DesktopApi', () => { it('DesktopApi.cancelUpdate', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.cancelUpdate(); - expect(spy).toBeCalledWith('update/cancel'); + expect(spy).toHaveBeenCalledWith('update/cancel'); // @ts-expect-error no expected params api.cancelUpdate(true); @@ -112,23 +112,23 @@ describe('DesktopApi', () => { it('DesktopApi.allowPrerelease', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.allowPrerelease(true); - expect(spy).toBeCalledWith('update/allow-prerelease', true); + expect(spy).toHaveBeenCalledWith('update/allow-prerelease', true); // @ts-expect-error invalid param api.allowPrerelease('string'); - expect(spy).toBeCalledTimes(1); // invalid param not processed + expect(spy).toHaveBeenCalledTimes(1); // invalid param not processed }); it('DesktopApi.themeChange', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.themeChange('dark'); - expect(spy).toBeCalledWith('theme/change', 'dark'); + expect(spy).toHaveBeenCalledWith('theme/change', 'dark'); // @ts-expect-error invalid theme api.themeChange('foo'); // @ts-expect-error param is required api.themeChange(); - expect(spy).toBeCalledTimes(1); // invalid param not processed + expect(spy).toHaveBeenCalledTimes(1); // invalid param not processed }); it('DesktopApi.metadataWrite', async () => { @@ -137,7 +137,7 @@ describe('DesktopApi', () => { .mockImplementation(() => Promise.resolve({ success: true })); const content = { file: 'file.txt', content: 'bar' }; const result = await api.metadataWrite(content); - expect(spy).toBeCalledWith('metadata/write', content); + expect(spy).toHaveBeenCalledWith('metadata/write', content); expect(result.success).toBe(true); if (result.success) { expect(result.payload).toBe(undefined); @@ -148,7 +148,7 @@ describe('DesktopApi', () => { // @ts-expect-error invalid params const fail = await api.metadataWrite({ file: 'file.txt' }); expect(fail.success).toBe(false); - expect(spy).toBeCalledTimes(1); // invalid param not processed + expect(spy).toHaveBeenCalledTimes(1); // invalid param not processed }); it('DesktopApi.metadataRead', async () => { @@ -160,7 +160,7 @@ describe('DesktopApi', () => { ); const content = { file: 'file.txt' }; const result = await api.metadataRead(content); - expect(spy).toBeCalledWith('metadata/read', content); + expect(spy).toHaveBeenCalledWith('metadata/read', content); expect(result.success).toBe(true); if (result.success) { expect(result.payload).toBe('file-content'); @@ -175,7 +175,7 @@ describe('DesktopApi', () => { api.metadataRead({ file: null }); // @ts-expect-error invalid params api.metadataRead(null); - expect(spy).toBeCalledTimes(1); // invalid params not processed + expect(spy).toHaveBeenCalledTimes(1); // invalid params not processed }); it('DesktopApi.getHttpReceiverAddress', async () => { @@ -183,19 +183,19 @@ describe('DesktopApi', () => { .spyOn(ipcRenderer, 'invoke') .mockImplementation(() => Promise.resolve('prefixed/coinmarket')); const result = await api.getHttpReceiverAddress('/coinmarket'); - expect(spy).toBeCalledWith('server/request-address', '/coinmarket'); + expect(spy).toHaveBeenCalledWith('server/request-address', '/coinmarket'); expect(result).toBe('prefixed/coinmarket'); // @ts-expect-error invalid params const fail = await api.getHttpReceiverAddress(true); expect(fail).toBe(undefined); - expect(spy).toBeCalledTimes(1); // invalid param not processed + expect(spy).toHaveBeenCalledTimes(1); // invalid param not processed }); it('DesktopApi.getTorStatus', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.getTorStatus(); - expect(spy).toBeCalledWith('tor/get-status'); + expect(spy).toHaveBeenCalledWith('tor/get-status'); // @ts-expect-error no expected params api.getTorStatus(true); @@ -204,17 +204,17 @@ describe('DesktopApi', () => { it('DesktopApi.toggleTor', () => { const spy = jest.spyOn(ipcRenderer, 'invoke'); api.toggleTor(true); - expect(spy).toBeCalledWith('tor/toggle', true); + expect(spy).toHaveBeenCalledWith('tor/toggle', true); // @ts-expect-error no expected params api.toggleTor('string'); - expect(spy).toBeCalledTimes(1); // invalid param not processed + expect(spy).toHaveBeenCalledTimes(1); // invalid param not processed }); it('DesktopApi.clearStore', () => { const spy = jest.spyOn(ipcRenderer, 'send'); api.clearStore(); - expect(spy).toBeCalledWith('store/clear'); + expect(spy).toHaveBeenCalledWith('store/clear'); // @ts-expect-error no expected params api.clearStore(true); @@ -225,7 +225,7 @@ describe('DesktopApi', () => { .spyOn(ipcRenderer, 'invoke') .mockImplementation(() => Promise.resolve({ success: true })); const result = await api.clearUserData(); - expect(spy).toBeCalledWith('user-data/clear'); + expect(spy).toHaveBeenCalledWith('user-data/clear'); expect(result.success).toBe(true); if (result.success) { expect(result.payload).toBe(undefined); @@ -243,12 +243,12 @@ describe('DesktopApi', () => { .mockImplementation(() => Promise.resolve({ success: true })); const result = await api.openUserDataDirectory(); - expect(spy).toBeCalledWith('user-data/open', ''); + expect(spy).toHaveBeenCalledWith('user-data/open', ''); expect(result.success).toBe(true); const existingDirectory = '/metadata'; api.openUserDataDirectory(existingDirectory); - expect(spy).toBeCalledWith('user-data/open', existingDirectory); + expect(spy).toHaveBeenCalledWith('user-data/open', existingDirectory); }); it('DesktopApi.installUdevRules', async () => { @@ -256,7 +256,7 @@ describe('DesktopApi', () => { .spyOn(ipcRenderer, 'invoke') .mockImplementation(() => Promise.resolve({ success: true })); const result = await api.installUdevRules(); - expect(spy).toBeCalledWith('udev/install'); + expect(spy).toHaveBeenCalledWith('udev/install'); expect(result.success).toBe(true); if (result.success) { expect(result.payload).toBe(undefined); @@ -273,7 +273,7 @@ describe('DesktopApi', () => { .spyOn(ipcRenderer, 'invoke') .mockImplementation(() => Promise.resolve()); await api.handshake(); - expect(spy).toBeCalledWith('handshake/client'); + expect(spy).toHaveBeenCalledWith('handshake/client'); }); it('DesktopApi.loadModules', async () => { @@ -281,7 +281,7 @@ describe('DesktopApi', () => { .spyOn(ipcRenderer, 'invoke') .mockImplementation(() => Promise.resolve({ success: true })); const data = await api.loadModules(null); - expect(spy).toBeCalledWith('handshake/load-modules', null); + expect(spy).toHaveBeenCalledWith('handshake/load-modules', null); expect(data.success).toBe(true); // @ts-expect-error param expected diff --git a/packages/suite/src/actions/wallet/__tests__/blockchainActions.test.ts b/packages/suite/src/actions/wallet/__tests__/blockchainActions.test.ts index afb1730f71..143886cf1e 100644 --- a/packages/suite/src/actions/wallet/__tests__/blockchainActions.test.ts +++ b/packages/suite/src/actions/wallet/__tests__/blockchainActions.test.ts @@ -98,7 +98,7 @@ describe('Blockchain Actions', () => { const store = initStore(getInitialState(f.initialState as Args)); await store.dispatch(initBlockchainThunk()); expect(filterThunkActionTypes(store.getActions())).toMatchObject(f.actions); - expect(TrezorConnect.blockchainSetCustomBackend).toBeCalledTimes( + expect(TrezorConnect.blockchainSetCustomBackend).toHaveBeenCalledTimes( f.blockchainSetCustomBackend, ); }); @@ -110,8 +110,10 @@ describe('Blockchain Actions', () => { const store = initStore(getInitialState(f.initialState as Args)); await store.dispatch(onBlockchainConnectThunk(f.symbol)); expect(filterThunkActionTypes(store.getActions())).toMatchObject(f.actions); - expect(TrezorConnect.blockchainEstimateFee).toBeCalledTimes(f.blockchainEstimateFee); - expect(TrezorConnect.blockchainSubscribe).toBeCalledTimes(f.blockchainSubscribe); + expect(TrezorConnect.blockchainEstimateFee).toHaveBeenCalledTimes( + f.blockchainEstimateFee, + ); + expect(TrezorConnect.blockchainSubscribe).toHaveBeenCalledTimes(f.blockchainSubscribe); }); }); @@ -131,7 +133,7 @@ describe('Blockchain Actions', () => { const timeout = actions[0].payload.time - new Date().getTime() + 500; jest.setTimeout(10000); await new Promise(resolve => setTimeout(resolve, timeout)); - expect(TrezorConnect.blockchainUnsubscribeFiatRates).toBeCalledTimes(1); + expect(TrezorConnect.blockchainUnsubscribeFiatRates).toHaveBeenCalledTimes(1); } }); }); @@ -142,7 +144,7 @@ describe('Blockchain Actions', () => { const store = initStore(getInitialState(f.initialState as Args)); await store.dispatch(onBlockchainNotificationThunk(f.params as any)); expect(filterThunkActionTypes(store.getActions())).toMatchObject(f.actions); - expect(TrezorConnect.getAccountInfo).toBeCalledTimes(f.getAccountInfo); + expect(TrezorConnect.getAccountInfo).toHaveBeenCalledTimes(f.getAccountInfo); }); }); @@ -190,7 +192,7 @@ describe('Blockchain Actions', () => { it(`customBackend: ${f.description}`, async () => { const store = initStore(getInitialState(f.initialState as any)); await store.dispatch(setCustomBackendThunk(f.symbol)); - expect(TrezorConnect.blockchainSetCustomBackend).toBeCalledTimes( + expect(TrezorConnect.blockchainSetCustomBackend).toHaveBeenCalledTimes( f.blockchainSetCustomBackend, ); }); @@ -213,7 +215,7 @@ describe('Blockchain Actions', () => { await store.dispatch(updateFeeInfoThunk('btc-invalid')); // will not trigger update because of blockHeight's await store.dispatch(updateFeeInfoThunk('btc')); - expect(TrezorConnect.blockchainEstimateFee).toBeCalledTimes(0); + expect(TrezorConnect.blockchainEstimateFee).toHaveBeenCalledTimes(0); // preload fee info failed in connect testMocks.setTrezorConnectFixtures({ success: false }); diff --git a/packages/suite/src/actions/wallet/__tests__/coinjoinClientActions.test.ts b/packages/suite/src/actions/wallet/__tests__/coinjoinClientActions.test.ts index 71c92965b9..3a2e6303f3 100644 --- a/packages/suite/src/actions/wallet/__tests__/coinjoinClientActions.test.ts +++ b/packages/suite/src/actions/wallet/__tests__/coinjoinClientActions.test.ts @@ -114,7 +114,9 @@ describe('coinjoinClientActions', () => { expect(actions.map(a => a.type)).toEqual(f.result.actions); if (typeof f.result.trezorConnectCalledTimes === 'number') { - expect(TrezorConnect.setBusy).toBeCalledTimes(f.result.trezorConnectCalledTimes); + expect(TrezorConnect.setBusy).toHaveBeenCalledTimes( + f.result.trezorConnectCalledTimes, + ); } if (f.result.trezorConnectCallsWith) { expect(TrezorConnect.setBusy).toHaveBeenLastCalledWith( @@ -133,7 +135,7 @@ describe('coinjoinClientActions', () => { expect(response).toMatchObject(f.result.response); - expect(TrezorConnect.getOwnershipProof).toBeCalledTimes( + expect(TrezorConnect.getOwnershipProof).toHaveBeenCalledTimes( f.result.trezorConnectCalledTimes, ); }); @@ -148,7 +150,7 @@ describe('coinjoinClientActions', () => { onCoinjoinClientRequest([f.params as any]), // params are incomplete ); - expect(TrezorConnect.signTransaction).toBeCalledTimes( + expect(TrezorConnect.signTransaction).toHaveBeenCalledTimes( f.result.trezorConnectCalledTimes, ); @@ -301,17 +303,17 @@ describe('coinjoinClientActions', () => { store.dispatch(clientEmitException('Some exception')); - expect(cli1.client.emit).toBeCalledTimes(1); - expect(cli2.client.emit).toBeCalledTimes(1); - expect(cli2.client.emit).toBeCalledWith('log', { + expect(cli1.client.emit).toHaveBeenCalledTimes(1); + expect(cli2.client.emit).toHaveBeenCalledTimes(1); + expect(cli2.client.emit).toHaveBeenCalledWith('log', { level: 'error', payload: 'Some exception', }); store.dispatch(clientEmitException('Other exception', { symbol: 'btc' })); - expect(cli1.client.emit).toBeCalledTimes(2); - expect(cli2.client.emit).toBeCalledTimes(1); + expect(cli1.client.emit).toHaveBeenCalledTimes(2); + expect(cli2.client.emit).toHaveBeenCalledTimes(1); }); it('clientEmitException from coinjoinMiddleware', async () => { @@ -343,7 +345,7 @@ describe('coinjoinClientActions', () => { if (!cli) throw new Error('Client not initialized'); store.dispatch({ type: '@suite/online-status', payload: false }); - expect(cli.client.emit).toBeCalledTimes(1); + expect(cli.client.emit).toHaveBeenCalledTimes(1); // restore session after previous action, and set phase to critical again // NOTE: dispatching { type: '@suite/tor-status', payload: 'Enabled' } requires a lot more fixtures @@ -360,11 +362,11 @@ describe('coinjoinClientActions', () => { restoreSession(); store.dispatch({ type: '@suite/tor-status', payload: 'Disabled' }); - expect(cli.client.emit).toBeCalledTimes(2); + expect(cli.client.emit).toHaveBeenCalledTimes(2); restoreSession(); store.dispatch({ type: 'device-disconnect', payload: { id: 'device-id' } }); - expect(cli.client.emit).toBeCalledTimes(3); + expect(cli.client.emit).toHaveBeenCalledTimes(3); // previous action stops the session const store2 = initializeStore(); @@ -373,7 +375,7 @@ describe('coinjoinClientActions', () => { type: '@common/wallet-core/accounts/removeAccount', payload: [{ key: 'btc-account1' }], }); - expect(cli.client.emit).toBeCalledTimes(4); + expect(cli.client.emit).toHaveBeenCalledTimes(4); }); // for coverage: edge cases, missing data etc... @@ -407,7 +409,7 @@ describe('coinjoinClientActions', () => { store.dispatch(stopCoinjoinSession('account-A')); - expect(TrezorConnect.cancelCoinjoinAuthorization).toBeCalledTimes(1); + expect(TrezorConnect.cancelCoinjoinAuthorization).toHaveBeenCalledTimes(1); }); it('stopCoinjoinSession but not cancel authorization', async () => { @@ -441,7 +443,7 @@ describe('coinjoinClientActions', () => { store.dispatch(stopCoinjoinSession('account-A')); - expect(TrezorConnect.cancelCoinjoinAuthorization).toBeCalledTimes(0); + expect(TrezorConnect.cancelCoinjoinAuthorization).toHaveBeenCalledTimes(0); }); it('CoinjoinClient events', async () => { diff --git a/packages/suite/src/hooks/wallet/__tests__/useExcludedUtxos.test.tsx b/packages/suite/src/hooks/wallet/__tests__/useExcludedUtxos.test.tsx index 91585eae30..95084df635 100644 --- a/packages/suite/src/hooks/wallet/__tests__/useExcludedUtxos.test.tsx +++ b/packages/suite/src/hooks/wallet/__tests__/useExcludedUtxos.test.tsx @@ -85,7 +85,7 @@ describe('useExcludedUtxos', () => { if (!props.account.addresses) throw new Error('invalid props'); const { unmount, rerender } = render(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(1); + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(1); expect(screen.getAllByTestId('utxo').length).toBe(1); expect(getRenders()).toBe(1); @@ -100,25 +100,25 @@ describe('useExcludedUtxos', () => { ]; rerender(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(2); + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(2); expect(screen.getAllByTestId('utxo').length).toBe(2); expect(getRenders()).toBe(2); props.account.addresses.anonymitySet = { AA01: 10, AA02: 10, AA03: 10 }; rerender(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(3); + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(3); expect(getRenders()).toBe(3); expect(() => screen.getAllByTestId('utxo')).toThrow('Unable to find an element'); delete props.account.addresses.anonymitySet; rerender(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(4); + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(4); expect(getRenders()).toBe(4); expect(screen.getAllByTestId('utxo').length).toBe(3); // default anonymitySet is used props.account.balance = '1000'; rerender(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(4); // changing balance should not trigger calculation + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(4); // changing balance should not trigger calculation expect(getRenders()).toBe(4); unmount(); @@ -129,13 +129,13 @@ describe('useExcludedUtxos', () => { if (!props.targetAnonymity) throw new Error('invalid props'); const { unmount, rerender } = render(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(1); + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(1); expect(screen.getAllByText('low-anonymity').length).toBe(1); expect(getRenders()).toBe(1); props.targetAnonymity = 1; rerender(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(2); + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(2); expect(getRenders()).toBe(2); expect(() => screen.getAllByTestId('utxo')).toThrow('Unable to find an element'); @@ -148,13 +148,13 @@ describe('useExcludedUtxos', () => { props.dustLimit = 20000; const { unmount, rerender } = render(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(1); + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(1); expect(getRenders()).toBe(1); expect(screen.getAllByText('dust').length).toBe(2); props.dustLimit = 100; rerender(); - expect(walletUtils.getExcludedUtxos).toBeCalledTimes(2); + expect(walletUtils.getExcludedUtxos).toHaveBeenCalledTimes(2); expect(getRenders()).toBe(2); expect(() => screen.getAllByText('dust')).toThrow('Unable to find an element'); diff --git a/packages/suite/src/hooks/wallet/__tests__/useRbfForm.test.tsx b/packages/suite/src/hooks/wallet/__tests__/useRbfForm.test.tsx index c57235b726..ac12443da7 100644 --- a/packages/suite/src/hooks/wallet/__tests__/useRbfForm.test.tsx +++ b/packages/suite/src/hooks/wallet/__tests__/useRbfForm.test.tsx @@ -155,7 +155,7 @@ describe('useRbfForm hook', () => { // validate number of calls to '@trezor/connect' if (typeof f.composeTransactionCalls === 'number') { - expect(composeTransactionSpy).toBeCalledTimes(f.composeTransactionCalls); + expect(composeTransactionSpy).toHaveBeenCalledTimes(f.composeTransactionCalls); } if (f.decreasedOutputs) { @@ -181,12 +181,12 @@ describe('useRbfForm hook', () => { if (f.signedTx) { // send and check signTransaction params await sendAction(); - expect(signTransactionMock).toBeCalledTimes(1); + expect(signTransactionMock).toHaveBeenCalledTimes(1); const params = signTransactionMock.mock.calls[0][0]; expect(params).toMatchObject(f.signedTx); } else { await expect(sendAction()).rejects.toThrow('Unable to perform pointer interaction'); // button `pointer-events: none` - expect(signTransactionMock).toBeCalledTimes(0); + expect(signTransactionMock).toHaveBeenCalledTimes(0); } unmount(); diff --git a/packages/suite/src/hooks/wallet/__tests__/useSendForm.test.tsx b/packages/suite/src/hooks/wallet/__tests__/useSendForm.test.tsx index 891f175ce4..95a26d357d 100644 --- a/packages/suite/src/hooks/wallet/__tests__/useSendForm.test.tsx +++ b/packages/suite/src/hooks/wallet/__tests__/useSendForm.test.tsx @@ -108,13 +108,15 @@ const actionCallback = ( // validate number of calls to '@trezor/connect' if (typeof result.composeTransactionCalls === 'number') { - expect(TrezorConnect.composeTransaction).toBeCalledTimes(result.composeTransactionCalls); + expect(TrezorConnect.composeTransaction).toHaveBeenCalledTimes( + result.composeTransactionCalls, + ); } if (typeof result.estimateFeeCalls === 'number') { - expect(TrezorConnect.blockchainEstimateFee).toBeCalledTimes(result.estimateFeeCalls); + expect(TrezorConnect.blockchainEstimateFee).toHaveBeenCalledTimes(result.estimateFeeCalls); } if (typeof result.getAccountInfoCalls === 'number') { - expect(TrezorConnect.getAccountInfo).toBeCalledTimes(result.getAccountInfoCalls); + expect(TrezorConnect.getAccountInfo).toHaveBeenCalledTimes(result.getAccountInfoCalls); } // validate '@trezor/connect' params diff --git a/packages/suite/src/middlewares/wallet/__tests__/coinmarketMiddleware.test.ts b/packages/suite/src/middlewares/wallet/__tests__/coinmarketMiddleware.test.ts index acabfc64f3..f8cad368f3 100644 --- a/packages/suite/src/middlewares/wallet/__tests__/coinmarketMiddleware.test.ts +++ b/packages/suite/src/middlewares/wallet/__tests__/coinmarketMiddleware.test.ts @@ -113,8 +113,8 @@ describe('coinmarketMiddleware', () => { { type: COINMARKET_COMMON.SET_LOADING, isLoading: true, lastLoadedTimestamp: 0 }, { type: COINMARKET_COMMON.LOAD_DATA }, ]); - expect(getCurrentAccountDescriptorMock).toBeCalledTimes(1); - expect(setInvityServersEnvironmentMock).toBeCalledTimes(1); + expect(getCurrentAccountDescriptorMock).toHaveBeenCalledTimes(1); + expect(setInvityServersEnvironmentMock).toHaveBeenCalledTimes(1); }); it('loadData - outdated data', () => { @@ -140,8 +140,8 @@ describe('coinmarketMiddleware', () => { { type: COINMARKET_COMMON.SET_LOADING, isLoading: true, lastLoadedTimestamp: 0 }, { type: COINMARKET_COMMON.LOAD_DATA }, ]); - expect(getCurrentAccountDescriptorMock).toBeCalledTimes(1); - expect(setInvityServersEnvironmentMock).toBeCalledTimes(1); + expect(getCurrentAccountDescriptorMock).toHaveBeenCalledTimes(1); + expect(setInvityServersEnvironmentMock).toHaveBeenCalledTimes(1); }); it('loadData - keep current data', () => { @@ -167,7 +167,7 @@ describe('coinmarketMiddleware', () => { store.dispatch({ type: COINMARKET_COMMON.LOAD_DATA }); expect(store.getActions()).toEqual([{ type: COINMARKET_COMMON.LOAD_DATA }]); - expect(getCurrentAccountDescriptorMock).toBeCalledTimes(1); - expect(setInvityServersEnvironmentMock).toBeCalledTimes(0); + expect(getCurrentAccountDescriptorMock).toHaveBeenCalledTimes(1); + expect(setInvityServersEnvironmentMock).toHaveBeenCalledTimes(0); }); }); diff --git a/packages/suite/src/middlewares/wallet/__tests__/walletMiddleware.test.ts b/packages/suite/src/middlewares/wallet/__tests__/walletMiddleware.test.ts index 1b889859e1..e6da47c2f6 100644 --- a/packages/suite/src/middlewares/wallet/__tests__/walletMiddleware.test.ts +++ b/packages/suite/src/middlewares/wallet/__tests__/walletMiddleware.test.ts @@ -114,7 +114,7 @@ describe('walletMiddleware', () => { const { subscribe, disconnect } = f.result; if (subscribe) { - expect(TrezorConnect.blockchainSubscribe).toBeCalledTimes(subscribe.called); + expect(TrezorConnect.blockchainSubscribe).toHaveBeenCalledTimes(subscribe.called); if (subscribe.called) { // @ts-expect-error const accounts = subscribe.accounts?.map(a => getWalletAccount(a)); @@ -126,7 +126,7 @@ describe('walletMiddleware', () => { } if (disconnect) { - expect(TrezorConnect.blockchainDisconnect).toBeCalledTimes(disconnect.called); + expect(TrezorConnect.blockchainDisconnect).toHaveBeenCalledTimes(disconnect.called); } }); }); diff --git a/packages/transport/tests/abstractUsb.test.ts b/packages/transport/tests/abstractUsb.test.ts index 44da1b3ead..60ce43df90 100644 --- a/packages/transport/tests/abstractUsb.test.ts +++ b/packages/transport/tests/abstractUsb.test.ts @@ -382,15 +382,15 @@ describe('Usb', () => { // count encoded/sent chunks await send(64); // default usb - expect(writeSpy).toBeCalledTimes(4); + expect(writeSpy).toHaveBeenCalledTimes(4); writeSpy.mockClear(); await send(16); // smaller chunks - expect(writeSpy).toBeCalledTimes(15); + expect(writeSpy).toHaveBeenCalledTimes(15); writeSpy.mockClear(); await send(128); // bigger chunks - expect(writeSpy).toBeCalledTimes(2); + expect(writeSpy).toHaveBeenCalledTimes(2); writeSpy.mockClear(); }); diff --git a/packages/utils/tests/scheduleAction.test.ts b/packages/utils/tests/scheduleAction.test.ts index a20270840c..82e09c7644 100644 --- a/packages/utils/tests/scheduleAction.test.ts +++ b/packages/utils/tests/scheduleAction.test.ts @@ -8,10 +8,10 @@ describe('scheduleAction', () => { it('delay', done => { const spy = jest.fn(() => Promise.resolve()); scheduleAction(spy, { delay: 1000 }); - expect(spy).toBeCalledTimes(0); + expect(spy).toHaveBeenCalledTimes(0); setTimeout(() => { - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); done(); }, 1005); }); @@ -21,7 +21,7 @@ describe('scheduleAction', () => { const spy = jest.fn(() => Promise.resolve()); scheduleAction(spy, { delay: 1000, signal: aborter.signal }).catch(e => { expect(e.message).toMatch(ERR_SIGNAL); - expect(spy).toBeCalledTimes(0); + expect(spy).toHaveBeenCalledTimes(0); done(); }); @@ -59,7 +59,7 @@ describe('scheduleAction', () => { scheduleAction(spy, { deadline: Date.now() + 1000, signal: aborter.signal }), ).rejects.toThrow(ERR_SIGNAL); - expect(spy).toBeCalledTimes(3); + expect(spy).toHaveBeenCalledTimes(3); }); it('deadline resolved after 3rd attempt', async () => { @@ -77,7 +77,7 @@ describe('scheduleAction', () => { expect(result).toEqual('Foo'); - expect(spy).toBeCalledTimes(3); + expect(spy).toHaveBeenCalledTimes(3); }); it('attempt timeout', async () => { @@ -88,7 +88,7 @@ describe('scheduleAction', () => { }), ); await expect(() => scheduleAction(spy, { timeout: 500 })).rejects.toThrow(ERR_TIMEOUT); - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); }); it('attempt timeout aborted', done => { @@ -103,7 +103,7 @@ describe('scheduleAction', () => { const start = Date.now(); scheduleAction(spy, { timeout: 300, signal: aborter.signal }).catch(e => { expect(e.message).toMatch(ERR_SIGNAL); - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); expect(Date.now() - start).toBeLessThanOrEqual(305); done(); @@ -123,7 +123,7 @@ describe('scheduleAction', () => { await expect(() => scheduleAction(spy, { deadline: Date.now() + 2000, timeout: 500 }), ).rejects.toThrow(ERR_DEADLINE); - expect(spy).toBeCalledTimes(4); // 4 attempts till deadline, each timeouted after 500 ms + expect(spy).toHaveBeenCalledTimes(4); // 4 attempts till deadline, each timeouted after 500 ms }); it('max attempts', async () => { @@ -135,7 +135,7 @@ describe('scheduleAction', () => { /Runtime error/, ); - expect(spy).toBeCalledTimes(2); + expect(spy).toHaveBeenCalledTimes(2); }); it("don't abort after success", async () => { diff --git a/suite-common/transaction-cache-engine/src/tests/TransactionCacheEngine.test.ts b/suite-common/transaction-cache-engine/src/tests/TransactionCacheEngine.test.ts index 1745817d15..a975eda116 100644 --- a/suite-common/transaction-cache-engine/src/tests/TransactionCacheEngine.test.ts +++ b/suite-common/transaction-cache-engine/src/tests/TransactionCacheEngine.test.ts @@ -42,8 +42,8 @@ describe('TransactionCacheEngine', () => { await engine.addAccount(account); expect(await engine.accountExists(account)).toBe(true); // should call getAccountInfo and blockchainSubscribe - expect(TrezorConnect.getAccountInfo).toBeCalled(); - expect(TrezorConnect.blockchainSubscribe).toBeCalled(); + expect(TrezorConnect.getAccountInfo).toHaveBeenCalled(); + expect(TrezorConnect.blockchainSubscribe).toHaveBeenCalled(); }); it('should remove an account', async () => { @@ -59,7 +59,7 @@ describe('TransactionCacheEngine', () => { await engine.removeAccount(account); expect(await engine.accountExists(account)).toBe(false); // should call blockchainUnsubscribe - expect(TrezorConnect.blockchainUnsubscribe).toBeCalled(); + expect(TrezorConnect.blockchainUnsubscribe).toHaveBeenCalled(); }); it('should get transactions', async () => {