diff --git a/jest.config.packages.js b/jest.config.packages.js index 89c610463f1..96bde23bfc7 100644 --- a/jest.config.packages.js +++ b/jest.config.packages.js @@ -108,8 +108,7 @@ module.exports = { // "resetMocks" resets all mocks, including mocked modules, to jest.fn(), // between each test case. - // TODO: Enable - // resetMocks: true, + resetMocks: true, // Reset the module registry before running each individual test // resetModules: false, diff --git a/jest.config.scripts.js b/jest.config.scripts.js index a86dd27b949..fe5792a9b6b 100644 --- a/jest.config.scripts.js +++ b/jest.config.scripts.js @@ -50,6 +50,10 @@ module.exports = { // // A preset that is used as a base for Jest's configuration // preset: 'ts-jest', + // "resetMocks" resets all mocks, including mocked modules, to jest.fn(), + // between each test case. + resetMocks: true, + // "restoreMocks" restores all mocks created using jest.spyOn to their // original implementations, between each test. It does not affect mocked // modules. diff --git a/packages/accounts-controller/src/AccountsController.test.ts b/packages/accounts-controller/src/AccountsController.test.ts index f82aa0eb334..1a600001926 100644 --- a/packages/accounts-controller/src/AccountsController.test.ts +++ b/packages/accounts-controller/src/AccountsController.test.ts @@ -315,10 +315,6 @@ function setupAccountsController({ } describe('AccountsController', () => { - afterEach(() => { - jest.resetAllMocks(); - }); - describe('onSnapStateChange', () => { it('be used enable an account if the Snap is enabled and not blocked', async () => { const messenger = buildMessenger(); @@ -449,9 +445,6 @@ describe('AccountsController', () => { }); describe('onKeyringStateChange', () => { - afterEach(() => { - jest.clearAllMocks(); - }); it('not update state when only keyring is unlocked without any keyrings', async () => { const messenger = buildMessenger(); const { accountsController } = setupAccountsController({ @@ -1304,10 +1297,6 @@ describe('AccountsController', () => { ); }); - afterEach(() => { - jest.clearAllMocks(); - }); - it('update accounts with normal accounts', async () => { mockUUID.mockReturnValueOnce('mock-id').mockReturnValueOnce('mock-id2'); const messenger = buildMessenger(); diff --git a/packages/approval-controller/src/ApprovalController.test.ts b/packages/approval-controller/src/ApprovalController.test.ts index 11cb6a8b265..fe190895280 100644 --- a/packages/approval-controller/src/ApprovalController.test.ts +++ b/packages/approval-controller/src/ApprovalController.test.ts @@ -2,6 +2,7 @@ import { ControllerMessenger } from '@metamask/base-controller'; import { errorCodes, JsonRpcError } from '@metamask/rpc-errors'; +import { nanoid } from 'nanoid'; import type { AddApprovalOptions, @@ -24,9 +25,9 @@ import { NoApprovalFlowsError, } from './errors'; -jest.mock('nanoid', () => ({ - nanoid: jest.fn(() => 'TestId'), -})); +jest.mock('nanoid'); + +const nanoidMock = jest.mocked(nanoid); const PENDING_APPROVALS_STORE_KEY = 'pendingApprovals'; const APPROVAL_FLOWS_STORE_KEY = 'approvalFlows'; @@ -243,6 +244,7 @@ describe('approval controller', () => { let showApprovalRequest: jest.Mock; beforeEach(() => { + nanoidMock.mockReturnValue('TestId'); jest.spyOn(global.console, 'info').mockImplementation(() => undefined); showApprovalRequest = jest.fn(); diff --git a/packages/assets-controllers/src/CurrencyRateController.test.ts b/packages/assets-controllers/src/CurrencyRateController.test.ts index d322e4be3bf..0dd2e82aa8d 100644 --- a/packages/assets-controllers/src/CurrencyRateController.test.ts +++ b/packages/assets-controllers/src/CurrencyRateController.test.ts @@ -75,7 +75,6 @@ describe('CurrencyRateController', () => { afterEach(() => { clock.restore(); - jest.restoreAllMocks(); }); it('should set default state', () => { diff --git a/packages/assets-controllers/src/RatesController/RatesController.test.ts b/packages/assets-controllers/src/RatesController/RatesController.test.ts index aea62d27be0..17e00f33266 100644 --- a/packages/assets-controllers/src/RatesController/RatesController.test.ts +++ b/packages/assets-controllers/src/RatesController/RatesController.test.ts @@ -90,10 +90,6 @@ function setupRatesController({ describe('RatesController', () => { let clock: sinon.SinonFakeTimers; - afterEach(() => { - jest.resetAllMocks(); - }); - describe('construct', () => { it('constructs the RatesController with default values', () => { const ratesController = setupRatesController({ @@ -116,7 +112,6 @@ describe('RatesController', () => { afterEach(() => { clock.restore(); - jest.restoreAllMocks(); }); it('starts the polling process with default values', async () => { @@ -249,7 +244,6 @@ describe('RatesController', () => { afterEach(() => { clock.restore(); - jest.restoreAllMocks(); }); it('stops the polling process', async () => { diff --git a/packages/assets-controllers/src/TokenListController.test.ts b/packages/assets-controllers/src/TokenListController.test.ts index 790f68b045c..d6f04de76d4 100644 --- a/packages/assets-controllers/src/TokenListController.test.ts +++ b/packages/assets-controllers/src/TokenListController.test.ts @@ -517,7 +517,6 @@ const getRestrictedMessenger = ( describe('TokenListController', () => { afterEach(() => { - jest.restoreAllMocks(); jest.clearAllTimers(); sinon.restore(); }); diff --git a/packages/assets-controllers/src/TokenRatesController.test.ts b/packages/assets-controllers/src/TokenRatesController.test.ts index 3f8404ae36a..4ba07c9cb55 100644 --- a/packages/assets-controllers/src/TokenRatesController.test.ts +++ b/packages/assets-controllers/src/TokenRatesController.test.ts @@ -81,10 +81,6 @@ function buildTokenRatesControllerMessenger( } describe('TokenRatesController', () => { - afterEach(() => { - jest.restoreAllMocks(); - }); - describe('constructor', () => { let clock: sinon.SinonFakeTimers; diff --git a/packages/assets-controllers/src/TokensController.test.ts b/packages/assets-controllers/src/TokensController.test.ts index 38692b64041..3d30994470b 100644 --- a/packages/assets-controllers/src/TokensController.test.ts +++ b/packages/assets-controllers/src/TokensController.test.ts @@ -77,7 +77,6 @@ describe('TokensController', () => { afterEach(() => { sinon.restore(); - jest.resetAllMocks(); }); it('should set default state', async () => { diff --git a/packages/gas-fee-controller/src/GasFeeController.test.ts b/packages/gas-fee-controller/src/GasFeeController.test.ts index 2c4d59b02af..84d25a03dc8 100644 --- a/packages/gas-fee-controller/src/GasFeeController.test.ts +++ b/packages/gas-fee-controller/src/GasFeeController.test.ts @@ -298,7 +298,6 @@ describe('GasFeeController', () => { // eslint-disable-next-line @typescript-eslint/no-floating-promises blockTracker?.destroy(); sinon.restore(); - jest.clearAllMocks(); }); describe('constructor', () => { @@ -735,12 +734,6 @@ describe('GasFeeController', () => { describe('fetchGasFeeEstimates', () => { describe('when on any network supporting legacy gas estimation api', () => { - const defaultConstructorOptions = { - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), - }; const mockDetermineGasFeeCalculations = buildMockGasFeeStateLegacy(); beforeEach(() => { @@ -751,7 +744,10 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), networkControllerState: { networkConfigurations: { 'AAAA-BBBB-CCCC-DDDD': { @@ -792,7 +788,12 @@ describe('GasFeeController', () => { }); it('should update the state with a fetched set of estimates', async () => { - await setupGasFeeController(defaultConstructorOptions); + await setupGasFeeController({ + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), + }); await gasFeeController.fetchGasFeeEstimates(); @@ -802,7 +803,12 @@ describe('GasFeeController', () => { }); it('should return the same data that it puts into state', async () => { - await setupGasFeeController(defaultConstructorOptions); + await setupGasFeeController({ + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), + }); const estimateData = await gasFeeController.fetchGasFeeEstimates(); @@ -811,7 +817,10 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when getChainId returns a number input', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), getChainId: jest.fn().mockReturnValue(1), }); @@ -826,7 +835,10 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when getChainId returns a hexstring input', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), getChainId: jest.fn().mockReturnValue('0x1'), }); @@ -841,7 +853,10 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when nonRPCGasFeeApisDisabled is true', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), state: { ...buildMockGasFeeStateEthGasPrice(), nonRPCGasFeeApisDisabled: true, @@ -859,7 +874,10 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when nonRPCGasFeeApisDisabled is false', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), state: { ...buildMockGasFeeStateEthGasPrice(), nonRPCGasFeeApisDisabled: false, @@ -877,7 +895,10 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when getChainId returns a numeric string input', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), getChainId: jest.fn().mockReturnValue('1'), }); @@ -892,9 +913,6 @@ describe('GasFeeController', () => { }); describe('when on any network supporting EIP-1559', () => { - const defaultConstructorOptions = { - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - }; const mockDetermineGasFeeCalculations = buildMockGasFeeStateFeeMarket(); beforeEach(() => { @@ -905,7 +923,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), networkControllerState: { networkConfigurations: { 'AAAA-BBBB-CCCC-DDDD': { @@ -946,7 +964,9 @@ describe('GasFeeController', () => { }); it('should update the state with a fetched set of estimates', async () => { - await setupGasFeeController(defaultConstructorOptions); + await setupGasFeeController({ + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + }); await gasFeeController.fetchGasFeeEstimates(); @@ -956,7 +976,9 @@ describe('GasFeeController', () => { }); it('should return the same data that it puts into state', async () => { - await setupGasFeeController(defaultConstructorOptions); + await setupGasFeeController({ + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + }); const estimateData = await gasFeeController.fetchGasFeeEstimates(); @@ -965,7 +987,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations with a URL that contains the chain ID', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), getChainId: jest.fn().mockReturnValue('0x1'), }); @@ -979,31 +1001,6 @@ describe('GasFeeController', () => { }); }); describe('when passed a networkClientId in options object', () => { - const defaultConstructorOptions = { - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - networkControllerState: { - networksMetadata: { - goerli: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - sepolia: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - 'test-network-client-id': { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - }, - }, - }; const mockDetermineGasFeeCalculations = buildMockGasFeeStateFeeMarket(); beforeEach(() => { @@ -1014,7 +1011,29 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + networkControllerState: { + networksMetadata: { + goerli: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + sepolia: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + 'test-network-client-id': { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + }, + }, clientId: '99999', }); @@ -1049,7 +1068,29 @@ describe('GasFeeController', () => { describe("the chainId of the networkClientId matches the globally selected network's chainId", () => { it('should update the globally selected network state with a fetched set of estimates', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + networkControllerState: { + networksMetadata: { + goerli: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + sepolia: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + 'test-network-client-id': { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + }, + }, getChainId: jest.fn().mockReturnValue(ChainId.goerli), onNetworkDidChange: jest.fn(), }); @@ -1065,7 +1106,29 @@ describe('GasFeeController', () => { it('should update the gasFeeEstimatesByChainId state with a fetched set of estimates', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + networkControllerState: { + networksMetadata: { + goerli: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + sepolia: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + 'test-network-client-id': { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + }, + }, getChainId: jest.fn().mockReturnValue(ChainId.goerli), onNetworkDidChange: jest.fn(), }); @@ -1083,7 +1146,29 @@ describe('GasFeeController', () => { describe("the chainId of the networkClientId does not match the globally selected network's chainId", () => { it('should not update the globally selected network state with a fetched set of estimates', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + networkControllerState: { + networksMetadata: { + goerli: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + sepolia: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + 'test-network-client-id': { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + }, + }, getChainId: jest.fn().mockReturnValue(ChainId.mainnet), onNetworkDidChange: jest.fn(), }); @@ -1101,7 +1186,29 @@ describe('GasFeeController', () => { it('should update the gasFeeEstimatesByChainId state with a fetched set of estimates', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + networkControllerState: { + networksMetadata: { + goerli: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + sepolia: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + 'test-network-client-id': { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + }, + }, getChainId: jest.fn().mockReturnValue(ChainId.mainnet), onNetworkDidChange: jest.fn(), }); @@ -1117,7 +1224,31 @@ describe('GasFeeController', () => { }); it('should return the same data that it puts into state', async () => { - await setupGasFeeController(defaultConstructorOptions); + await setupGasFeeController({ + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + networkControllerState: { + networksMetadata: { + goerli: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + sepolia: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + 'test-network-client-id': { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + }, + }, + }); const estimateData = await gasFeeController.fetchGasFeeEstimates({ networkClientId: 'sepolia', @@ -1128,7 +1259,29 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations with a URL that contains the chain ID', async () => { await setupGasFeeController({ - ...defaultConstructorOptions, + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + networkControllerState: { + networksMetadata: { + goerli: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + sepolia: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + 'test-network-client-id': { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + }, + }, }); await gasFeeController.fetchGasFeeEstimates({ diff --git a/packages/gas-fee-controller/src/gas-util.test.ts b/packages/gas-fee-controller/src/gas-util.test.ts index b1e5647be84..d6829e7fc78 100644 --- a/packages/gas-fee-controller/src/gas-util.test.ts +++ b/packages/gas-fee-controller/src/gas-util.test.ts @@ -78,10 +78,6 @@ const INFURA_AUTH_TOKEN_MOCK = 'dGVzdDo='; const INFURA_GAS_API_URL_MOCK = 'https://gas.api.infura.io'; describe('gas utils', () => { - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('fetchGasEstimates', () => { it('should fetch external gasFeeEstimates when data is valid', async () => { handleFetchMock.mockResolvedValue(mockEIP1559ApiResponses[0]); diff --git a/packages/logging-controller/src/LoggingController.test.ts b/packages/logging-controller/src/LoggingController.test.ts index 0b8626ef1a9..3f092f56b4d 100644 --- a/packages/logging-controller/src/LoggingController.test.ts +++ b/packages/logging-controller/src/LoggingController.test.ts @@ -7,10 +7,11 @@ import { LogType } from './logTypes'; import { SigningMethod, SigningStage } from './logTypes/EthSignLog'; jest.mock('uuid', () => { - const actual = jest.requireActual('uuid'); return { - ...actual, - v1: jest.fn(() => actual.v1()), + // We need to use this name as this is what Jest recognizes. + // eslint-disable-next-line @typescript-eslint/naming-convention + __esModule: true, + ...jest.requireActual('uuid'), }; }); @@ -42,9 +43,6 @@ function getRestrictedMessenger( } describe('LoggingController', () => { - afterEach(() => { - jest.clearAllMocks(); - }); it('action: LoggingController:add with generic log', async () => { const unrestricted = getUnrestrictedMessenger(); const messenger = getRestrictedMessenger(unrestricted); @@ -112,6 +110,7 @@ describe('LoggingController', () => { it('action: LoggingController:add prevents possible collision of ids', async () => { const unrestricted = getUnrestrictedMessenger(); const messenger = getRestrictedMessenger(unrestricted); + const uuidV1Spy = jest.spyOn(uuid, 'v1'); const controller = new LoggingController({ messenger, @@ -128,9 +127,7 @@ describe('LoggingController', () => { const { id } = Object.values(controller.state.logs)[0]; - if (jest.isMockFunction(uuid.v1)) { - uuid.v1.mockImplementationOnce(() => id); - } + uuidV1Spy.mockReturnValueOnce(id); expect( // TODO: Either fix this lint violation or explain why it's necessary to ignore. @@ -160,7 +157,7 @@ describe('LoggingController', () => { }), }); - expect(uuid.v1).toHaveBeenCalledTimes(3); + expect(uuidV1Spy).toHaveBeenCalledTimes(3); }); it('internal method: clear', async () => { diff --git a/packages/name-controller/src/NameController.test.ts b/packages/name-controller/src/NameController.test.ts index d05d3fa80a4..551d7eb2ff9 100644 --- a/packages/name-controller/src/NameController.test.ts +++ b/packages/name-controller/src/NameController.test.ts @@ -34,12 +34,6 @@ const CONTROLLER_ARGS_MOCK = { providers: [], }; -// eslint-disable-next-line jest/prefer-spy-on -console.error = jest.fn(); - -// eslint-disable-next-line jest/prefer-spy-on -Date.now = jest.fn().mockReturnValue(TIME_MOCK * 1000); - /** * Creates a mock name provider. * @@ -76,6 +70,14 @@ function createMockProvider( } describe('NameController', () => { + beforeEach(() => { + jest.spyOn(console, 'error').mockImplementation(() => { + // do nothing + }); + + jest.spyOn(Date, 'now').mockReturnValue(TIME_MOCK * 1000); + }); + describe('setName', () => { it('creates an entry if new%s', () => { const provider1 = createMockProvider(1); diff --git a/packages/name-controller/src/providers/ens.test.ts b/packages/name-controller/src/providers/ens.test.ts index 5166839e60a..126fb0cdcd7 100644 --- a/packages/name-controller/src/providers/ens.test.ts +++ b/packages/name-controller/src/providers/ens.test.ts @@ -16,10 +16,6 @@ const CONSTRUCTOR_ARGS_MOCK = { } as any; describe('ENSNameProvider', () => { - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('getMetadata', () => { it('returns the provider metadata', () => { const metadata = new ENSNameProvider(CONSTRUCTOR_ARGS_MOCK).getMetadata(); diff --git a/packages/name-controller/src/providers/etherscan.test.ts b/packages/name-controller/src/providers/etherscan.test.ts index dd8d89eff6e..78ae2d42e41 100644 --- a/packages/name-controller/src/providers/etherscan.test.ts +++ b/packages/name-controller/src/providers/etherscan.test.ts @@ -14,10 +14,6 @@ const CONTRACT_NAME_2_MOCK = 'TestContractName2'; describe('EtherscanNameProvider', () => { const handleFetchMock = jest.mocked(handleFetch); - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('getMetadata', () => { it('returns the provider metadata', () => { const metadata = new EtherscanNameProvider().getMetadata(); diff --git a/packages/name-controller/src/providers/lens.test.ts b/packages/name-controller/src/providers/lens.test.ts index 729bd504dc4..dc22770dbf3 100644 --- a/packages/name-controller/src/providers/lens.test.ts +++ b/packages/name-controller/src/providers/lens.test.ts @@ -13,10 +13,6 @@ const HANDLE_2_MOCK = 'TestHandle2'; describe('LensNameProvider', () => { const graphqlMock = jest.mocked(graphQL); - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('getMetadata', () => { it('returns the provider metadata', () => { const metadata = new LensNameProvider().getMetadata(); diff --git a/packages/name-controller/src/providers/token.test.ts b/packages/name-controller/src/providers/token.test.ts index 58bf6c172d2..4215e2dfe51 100644 --- a/packages/name-controller/src/providers/token.test.ts +++ b/packages/name-controller/src/providers/token.test.ts @@ -12,10 +12,6 @@ const TOKEN_NAME_MOCK = 'TestTokenName'; describe('TokenNameProvider', () => { const handleFetchMock = jest.mocked(handleFetch); - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('getMetadata', () => { it('returns the provider metadata', () => { const metadata = new TokenNameProvider().getMetadata(); diff --git a/packages/network-controller/tests/NetworkController.test.ts b/packages/network-controller/tests/NetworkController.test.ts index 2b3d924f343..7392a0956a5 100644 --- a/packages/network-controller/tests/NetworkController.test.ts +++ b/packages/network-controller/tests/NetworkController.test.ts @@ -153,10 +153,6 @@ const GENERIC_JSON_RPC_ERROR = rpcErrors.internal( ); describe('NetworkController', () => { - beforeEach(() => { - jest.resetAllMocks(); - }); - afterEach(() => { resetAllWhenMocks(); }); diff --git a/packages/permission-controller/src/PermissionController.test.ts b/packages/permission-controller/src/PermissionController.test.ts index 7f117be97a2..3595af9285b 100644 --- a/packages/permission-controller/src/PermissionController.test.ts +++ b/packages/permission-controller/src/PermissionController.test.ts @@ -774,10 +774,6 @@ function getPermissionMatcher({ } describe('PermissionController', () => { - beforeEach(() => { - jest.clearAllMocks(); - }); - describe('constructor', () => { it('initializes a new PermissionController', () => { const controller = getDefaultPermissionController(); diff --git a/packages/selected-network-controller/tests/SelectedNetworkController.test.ts b/packages/selected-network-controller/tests/SelectedNetworkController.test.ts index cbe603590f7..d97564c6bc1 100644 --- a/packages/selected-network-controller/tests/SelectedNetworkController.test.ts +++ b/packages/selected-network-controller/tests/SelectedNetworkController.test.ts @@ -203,10 +203,6 @@ const setup = ({ }; describe('SelectedNetworkController', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - describe('constructor', () => { it('can be instantiated with default values', () => { const { controller } = setup(); diff --git a/packages/signature-controller/src/SignatureController.test.ts b/packages/signature-controller/src/SignatureController.test.ts index d4eb1e07c43..1cf29e035c3 100644 --- a/packages/signature-controller/src/SignatureController.test.ts +++ b/packages/signature-controller/src/SignatureController.test.ts @@ -173,7 +173,6 @@ describe('SignatureController', () => { }; beforeEach(() => { - jest.resetAllMocks(); jest.spyOn(console, 'info').mockImplementation(() => undefined); addUnapprovedMessageMock.mockResolvedValue(messageIdMock); diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index ed7f8b6fb7b..f02b63baa1e 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -855,10 +855,6 @@ describe('TransactionController', () => { ); }); - afterEach(() => { - jest.resetAllMocks(); - }); - describe('constructor', () => { it('sets default state', () => { const { controller } = setupController(); diff --git a/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.test.ts b/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.test.ts index 154b911bd71..64d84fbdecf 100644 --- a/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.test.ts +++ b/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.test.ts @@ -60,8 +60,6 @@ describe('LineaGasFeeFlow', () => { let request: GasFeeFlowRequest; beforeEach(() => { - jest.resetAllMocks(); - request = { ethQuery: {} as EthQuery, transactionMeta: TRANSACTION_META_MOCK, diff --git a/packages/transaction-controller/src/helpers/EtherscanRemoteTransactionSource.test.ts b/packages/transaction-controller/src/helpers/EtherscanRemoteTransactionSource.test.ts index cab6442cd69..1c9bc290fdd 100644 --- a/packages/transaction-controller/src/helpers/EtherscanRemoteTransactionSource.test.ts +++ b/packages/transaction-controller/src/helpers/EtherscanRemoteTransactionSource.test.ts @@ -44,8 +44,6 @@ describe('EtherscanRemoteTransactionSource', () => { const randomMock = random as jest.MockedFn; beforeEach(() => { - jest.resetAllMocks(); - clock = sinon.useFakeTimers(); fetchEtherscanTransactionsMock.mockResolvedValue( diff --git a/packages/transaction-controller/src/helpers/GasFeePoller.test.ts b/packages/transaction-controller/src/helpers/GasFeePoller.test.ts index 91248f55464..bd62f1fa2d3 100644 --- a/packages/transaction-controller/src/helpers/GasFeePoller.test.ts +++ b/packages/transaction-controller/src/helpers/GasFeePoller.test.ts @@ -73,7 +73,6 @@ describe('GasFeePoller', () => { const findNetworkClientIdByChainIdMock = jest.fn(); beforeEach(() => { - jest.resetAllMocks(); jest.clearAllTimers(); gasFeeFlowMock = createGasFeeFlowMock(); diff --git a/packages/transaction-controller/src/helpers/IncomingTransactionHelper.test.ts b/packages/transaction-controller/src/helpers/IncomingTransactionHelper.test.ts index 4afe6c64ed0..837a561210f 100644 --- a/packages/transaction-controller/src/helpers/IncomingTransactionHelper.test.ts +++ b/packages/transaction-controller/src/helpers/IncomingTransactionHelper.test.ts @@ -129,10 +129,6 @@ async function emitBlockTrackerLatestEvent( } describe('IncomingTransactionHelper', () => { - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('on block tracker latest event', () => { // eslint-disable-next-line jest/expect-expect it('handles errors', async () => { diff --git a/packages/transaction-controller/src/helpers/MultichainTrackingHelper.test.ts b/packages/transaction-controller/src/helpers/MultichainTrackingHelper.test.ts index 69119be8e22..2b5fa6c546a 100644 --- a/packages/transaction-controller/src/helpers/MultichainTrackingHelper.test.ts +++ b/packages/transaction-controller/src/helpers/MultichainTrackingHelper.test.ts @@ -221,8 +221,6 @@ function newMultichainTrackingHelper( describe('MultichainTrackingHelper', () => { beforeEach(() => { - jest.resetAllMocks(); - for (const network of [ 'mainnet', 'goerli', diff --git a/packages/transaction-controller/src/helpers/PendingTransactionTracker.test.ts b/packages/transaction-controller/src/helpers/PendingTransactionTracker.test.ts index 0deb17f8ca8..920e90d75c1 100644 --- a/packages/transaction-controller/src/helpers/PendingTransactionTracker.test.ts +++ b/packages/transaction-controller/src/helpers/PendingTransactionTracker.test.ts @@ -85,8 +85,6 @@ describe('PendingTransactionTracker', () => { } beforeEach(() => { - jest.resetAllMocks(); - blockTracker = createBlockTrackerMock(); failTransaction = jest.fn(); diff --git a/packages/transaction-controller/src/utils/etherscan.test.ts b/packages/transaction-controller/src/utils/etherscan.test.ts index 9a54e575b44..6fd0d7e0ac1 100644 --- a/packages/transaction-controller/src/utils/etherscan.test.ts +++ b/packages/transaction-controller/src/utils/etherscan.test.ts @@ -34,10 +34,6 @@ const RESPONSE_MOCK: EtherscanTransactionResponse = { describe('Etherscan', () => { const handleFetchMock = jest.mocked(handleFetch); - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('getEtherscanApiHost', () => { it('returns Etherscan API host for supported network', () => { expect(getEtherscanApiHost(CHAIN_IDS.GOERLI)).toBe( diff --git a/packages/transaction-controller/src/utils/gas.test.ts b/packages/transaction-controller/src/utils/gas.test.ts index 53e66f73e81..b5dfebdf155 100644 --- a/packages/transaction-controller/src/utils/gas.test.ts +++ b/packages/transaction-controller/src/utils/gas.test.ts @@ -93,8 +93,6 @@ describe('gas', () => { } beforeEach(() => { - jest.resetAllMocks(); - updateGasRequest = JSON.parse(JSON.stringify(UPDATE_GAS_REQUEST_MOCK)); }); diff --git a/packages/transaction-controller/src/utils/simulation-api.test.ts b/packages/transaction-controller/src/utils/simulation-api.test.ts index 8ff5603051c..aafccb5282f 100644 --- a/packages/transaction-controller/src/utils/simulation-api.test.ts +++ b/packages/transaction-controller/src/utils/simulation-api.test.ts @@ -65,8 +65,6 @@ describe('Simulation API Utils', () => { } beforeEach(() => { - jest.resetAllMocks(); - fetchMock = jest.spyOn(global, 'fetch') as jest.MockedFunction< typeof fetch >; diff --git a/packages/transaction-controller/src/utils/simulation.test.ts b/packages/transaction-controller/src/utils/simulation.test.ts index 4d138b51ab2..60a742de491 100644 --- a/packages/transaction-controller/src/utils/simulation.test.ts +++ b/packages/transaction-controller/src/utils/simulation.test.ts @@ -266,7 +266,6 @@ describe('Simulation Utils', () => { const simulateTransactionsMock = jest.mocked(simulateTransactions); beforeEach(() => { - jest.resetAllMocks(); jest.spyOn(Interface.prototype, 'encodeFunctionData').mockReturnValue(''); }); diff --git a/packages/transaction-controller/src/utils/utils.test.ts b/packages/transaction-controller/src/utils/utils.test.ts index 14e3374ac45..8d7f1986b0e 100644 --- a/packages/transaction-controller/src/utils/utils.test.ts +++ b/packages/transaction-controller/src/utils/utils.test.ts @@ -25,10 +25,6 @@ const TRANSACTION_PARAMS_MOCK: TransactionParams = { }; describe('utils', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - describe('normalizeTransactionParams', () => { it('normalizes properties', () => { const normalized = util.normalizeTransactionParams( diff --git a/packages/transaction-controller/src/utils/validation.test.ts b/packages/transaction-controller/src/utils/validation.test.ts index 265f3e954d5..e26175022bd 100644 --- a/packages/transaction-controller/src/utils/validation.test.ts +++ b/packages/transaction-controller/src/utils/validation.test.ts @@ -4,10 +4,6 @@ import { TransactionEnvelopeType } from '../types'; import { validateTxParams } from './validation'; describe('validation', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - describe('validateTxParams', () => { it('should throw if no from address', () => { // TODO: Replace `any` with type diff --git a/packages/user-operation-controller/src/UserOperationController.test.ts b/packages/user-operation-controller/src/UserOperationController.test.ts index 6e9554d6957..e41af0e540f 100644 --- a/packages/user-operation-controller/src/UserOperationController.test.ts +++ b/packages/user-operation-controller/src/UserOperationController.test.ts @@ -192,8 +192,6 @@ describe('UserOperationController', () => { ); beforeEach(() => { - jest.resetAllMocks(); - jest.spyOn(BundlerHelper, 'Bundler').mockReturnValue(bundlerMock); jest .spyOn(PendingUserOperationTrackerHelper, 'PendingUserOperationTracker') diff --git a/packages/user-operation-controller/src/helpers/PendingUserOperationTracker.test.ts b/packages/user-operation-controller/src/helpers/PendingUserOperationTracker.test.ts index b3c16aa3585..2285f2cd90e 100644 --- a/packages/user-operation-controller/src/helpers/PendingUserOperationTracker.test.ts +++ b/packages/user-operation-controller/src/helpers/PendingUserOperationTracker.test.ts @@ -121,7 +121,6 @@ describe('PendingUserOperationTracker', () => { } beforeEach(() => { - jest.resetAllMocks(); jest.spyOn(BundlerHelper, 'Bundler').mockReturnValue(bundlerMock); messengerMock.call.mockReturnValue({ diff --git a/packages/user-operation-controller/src/helpers/SnapSmartContractAccount.test.ts b/packages/user-operation-controller/src/helpers/SnapSmartContractAccount.test.ts index 960ba8b7180..11475aa0386 100644 --- a/packages/user-operation-controller/src/helpers/SnapSmartContractAccount.test.ts +++ b/packages/user-operation-controller/src/helpers/SnapSmartContractAccount.test.ts @@ -89,8 +89,6 @@ describe('SnapSmartContractAccount', () => { let signMock: jest.MockedFn; beforeEach(() => { - jest.resetAllMocks(); - messengerMock = createMessengerMock(); prepareMock = jest.fn(); patchMock = jest.fn(); diff --git a/packages/user-operation-controller/src/utils/gas-fees.test.ts b/packages/user-operation-controller/src/utils/gas-fees.test.ts index 3d7e1fb5661..25cb1b1a0d2 100644 --- a/packages/user-operation-controller/src/utils/gas-fees.test.ts +++ b/packages/user-operation-controller/src/utils/gas-fees.test.ts @@ -34,8 +34,6 @@ describe('gas-fees', () => { let request: jest.Mocked; beforeEach(() => { - jest.resetAllMocks(); - request = cloneDeep(UPDATE_GAS_FEES_REQUEST_MOCK); jest diff --git a/scripts/create-package/commands.test.ts b/scripts/create-package/commands.test.ts index 97153222fbe..e557dd51506 100644 --- a/scripts/create-package/commands.test.ts +++ b/scripts/create-package/commands.test.ts @@ -13,10 +13,6 @@ jest.mock('./utils', () => ({ jest.useFakeTimers().setSystemTime(new Date('2023-01-02')); describe('create-package/commands', () => { - afterEach(() => { - jest.resetAllMocks(); - }); - describe('createPackageHandler', () => { it('should create the expected package', async () => { (utils.readMonorepoFiles as jest.Mock).mockResolvedValue({ diff --git a/scripts/create-package/utils.test.ts b/scripts/create-package/utils.test.ts index 263b52f2ec0..af903f8edec 100644 --- a/scripts/create-package/utils.test.ts +++ b/scripts/create-package/utils.test.ts @@ -29,10 +29,6 @@ jest.mock('./fs-utils', () => ({ })); describe('create-package/utils', () => { - afterEach(() => { - jest.resetAllMocks(); - }); - describe('readMonorepoFiles', () => { const tsConfig = JSON.stringify({ references: [{ path: '../packages/foo' }],