Skip to content

Commit

Permalink
test: update ut for connect
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkynz committed Mar 21, 2023
1 parent 2d0b95e commit cec95fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/actions/account/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ vi.mock('@casperdash/usewallet-core/utils/client', () => ({
getActivePublicKey: vi.fn(),
} as unknown as Connector,
setState: callBackSpy,
setLastUsedConnector: vi.fn(),
})),
}));

Expand Down Expand Up @@ -75,8 +76,8 @@ describe('connect', () => {
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const connector = {
id: 'test',
connect: vi.fn(),
getActivePublicKey: vi.fn().mockRejectedValueOnce(new ConnectorNotFoundError()),
connect: vi.fn().mockRejectedValueOnce(new ConnectorNotFoundError()),
getActivePublicKey: vi.fn(),
isConnected: vi.fn().mockResolvedValueOnce(true),
} as unknown as Connector;
const connectSpy = vi.spyOn(connector, 'connect');
Expand All @@ -88,7 +89,7 @@ describe('connect', () => {
}

expect(connectSpy).toHaveBeenCalledOnce();
expect(getActivePublicKeySpy).toHaveBeenCalledOnce();
expect(getActivePublicKeySpy).toBeCalledTimes(0);
expect(errorSpy).toHaveBeenCalledOnce();
});

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/connectors/casperSigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('CasperSignerConnector', () => {
it('should remove all event listeners from the event provider', async () => {
await connector.disconnect();

expect(eventProviderMock.removeEventListener).toHaveBeenCalledTimes(3);
expect(eventProviderMock.removeEventListener).toHaveBeenCalledTimes(4);
expect(eventProviderMock.removeEventListener).toHaveBeenCalledWith(
'signer:activeKeyChanged',
connector.onActiveKeyChanged,
Expand All @@ -201,10 +201,10 @@ describe('CasperSignerConnector', () => {
});

describe('connect', () => {
it('should add 3 event listeners to eventProvider', async () => {
it('should add 4 event listeners to eventProvider', async () => {
await connector.connect();

expect(eventProviderMock.addEventListener).toHaveBeenCalledTimes(3);
expect(eventProviderMock.addEventListener).toHaveBeenCalledTimes(4);
expect(eventProviderMock.addEventListener).toHaveBeenCalledWith(
'signer:activeKeyChanged',
connector.onActiveKeyChanged,
Expand Down

0 comments on commit cec95fc

Please sign in to comment.