Skip to content

Commit

Permalink
fix: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri committed Dec 20, 2024
1 parent ddc551b commit a6ce16e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/components/Views/Wallet/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Routes from '../../../constants/navigation/Routes';
import { backgroundState } from '../../../util/test/initial-root-state';
import { MOCK_ACCOUNTS_CONTROLLER_STATE } from '../../../util/test/accountsControllerTestUtils';
import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors';
import Engine from '../../../core/Engine';

const MOCK_ADDRESS = '0xc4955c0d639d99699bfd7ec54d9fafee40e4d272';

Expand Down Expand Up @@ -64,6 +65,9 @@ jest.mock('../../../core/Engine', () => {
PreferencesController: {
setTokenNetworkFilter: jest.fn(),
},
TokensController: {
addTokens: jest.fn(),
},
},
};
});
Expand Down Expand Up @@ -94,6 +98,10 @@ const mockInitialState = {
AccountsController: {
...MOCK_ACCOUNTS_CONTROLLER_STATE,
},
TokensController: {
...backgroundState.TokensController,
detectedTokens: [{ address: '0x123' }],
},
},
},
};
Expand Down Expand Up @@ -140,7 +148,6 @@ jest.mock('../../../util/address', () => ({
},
}),
}));

const render = (Component: React.ComponentType) =>
renderScreen(
Component,
Expand All @@ -153,6 +160,9 @@ const render = (Component: React.ComponentType) =>
);

describe('Wallet', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should render correctly', () => {
//@ts-expect-error we are ignoring the navigation params on purpose because we do not want to mock setOptions to test the navbar
const wrapper = render(Wallet);
Expand Down Expand Up @@ -187,4 +197,13 @@ describe('Wallet', () => {
);
expect(accountPicker).toBeDefined();
});

it('Should add tokens to state automatically when there are detected tokens', () => {
const mockedAddTokens = jest.mocked(Engine.context.TokensController);

//@ts-expect-error we are ignoring the navigation params on purpose because we do not want to mock setOptions to test the navbar
render(Wallet);

expect(mockedAddTokens.addTokens).toHaveBeenCalledTimes(1);
});
});

0 comments on commit a6ce16e

Please sign in to comment.