Skip to content

Commit

Permalink
feat: add test for change in currentCurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
montelaidev committed Nov 28, 2024
1 parent a917658 commit 9d4120e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,7 @@ describe('MetaMaskController', () => {
methods: [BtcMethod.SendBitcoin],
address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
};
const mockCurrency = 'CAD';

beforeEach(() => {
jest.spyOn(metamaskController.multichainRatesController, 'start');
Expand Down Expand Up @@ -2502,6 +2503,43 @@ describe('MetaMaskController', () => {
localMetamaskController.multichainRatesController.start,
).toHaveBeenCalled();
});

it('calls setFiatCurrency when the `currentCurrency` has changed', async () => {
jest.spyOn(RatesController.prototype, 'setFiatCurrency');
const localMetamaskController = new MetaMaskController({
showUserConfirmation: noop,
encryptor: mockEncryptor,
initState: {
...cloneDeep(firstTimeState),
AccountsController: {
internalAccounts: {
accounts: {
[mockNonEvmAccount.id]: mockNonEvmAccount,
[mockEvmAccount.id]: mockEvmAccount,
},
selectedAccount: mockNonEvmAccount.id,
},
},
},
initLangCode: 'en_US',
platform: {
showTransactionNotification: () => undefined,
getVersion: () => 'foo',
},
browser: browserPolyfillMock,
infuraProjectId: 'foo',
isFirstMetaMaskControllerSetup: true,
});

metamaskController.controllerMessenger.publish(
'CurrencyRateController:stateChange',
{ currentCurrency: mockCurrency },
);

expect(
localMetamaskController.multichainRatesController.setFiatCurrency,
).toHaveBeenCalledWith(mockCurrency);
});
});

describe('MultichainBalancesController', () => {
Expand Down

0 comments on commit 9d4120e

Please sign in to comment.