Skip to content

Commit 2bd05ad

Browse files
committed
test: add test
1 parent a99dd2a commit 2bd05ad

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

packages/accounts-controller/src/AccountsController.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,62 @@ describe('AccountsController', () => {
16341634
expect(selectedAccount.id).toStrictEqual(expectedSelectedId);
16351635
},
16361636
);
1637+
1638+
it('fires :accountAdded before :selectedAccountChange', async () => {
1639+
const messenger = buildMessenger();
1640+
1641+
mockUUIDWithNormalAccounts([mockAccount, mockAccount2]);
1642+
1643+
const { accountsController } = setupAccountsController({
1644+
initialState: {
1645+
internalAccounts: {
1646+
accounts: {},
1647+
selectedAccount: '',
1648+
},
1649+
},
1650+
messenger,
1651+
});
1652+
1653+
const mockNewKeyringState = {
1654+
isUnlocked: true,
1655+
keyrings: [
1656+
{
1657+
type: KeyringTypes.hd,
1658+
accounts: [mockAccount.address],
1659+
metadata: {
1660+
id: 'mock-id',
1661+
name: 'mock-name',
1662+
},
1663+
},
1664+
],
1665+
};
1666+
1667+
const mockEventsOrder = jest.fn();
1668+
1669+
messenger.subscribe('AccountsController:accountAdded', () => {
1670+
mockEventsOrder('AccountsController:accountAdded');
1671+
});
1672+
messenger.subscribe('AccountsController:selectedAccountChange', () => {
1673+
mockEventsOrder('AccountsController:selectedAccountChange');
1674+
});
1675+
1676+
expect(accountsController.getSelectedAccount()).toBe(EMPTY_ACCOUNT);
1677+
1678+
messenger.publish(
1679+
'KeyringController:stateChange',
1680+
mockNewKeyringState,
1681+
[],
1682+
);
1683+
1684+
expect(mockEventsOrder).toHaveBeenNthCalledWith(
1685+
1,
1686+
'AccountsController:accountAdded',
1687+
);
1688+
expect(mockEventsOrder).toHaveBeenNthCalledWith(
1689+
2,
1690+
'AccountsController:selectedAccountChange',
1691+
);
1692+
});
16371693
});
16381694

16391695
describe('onSnapKeyringEvents', () => {

0 commit comments

Comments
 (0)