Skip to content

Commit

Permalink
frontend: adjust useWallet composable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBuragev committed Feb 15, 2023
1 parent 54e8615 commit f183ae3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions frontend/tests/unit/composables/useWallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,42 @@ describe('useWallets', () => {
});
});

describe('connectWalletConnect()', () => {
it('creates WalletConnect 2 provider instance', async () => {
const rpcUrls = ref({ 5: 'fakeRpc.url' });
const { connectWalletConnect } = useWallet(ref(undefined), ref(undefined), rpcUrls);

await connectWalletConnect();

expect(web3ProviderService.createWalletConnectProvider).toHaveBeenCalledOnce();
expect(web3ProviderService.createWalletConnectProvider).toHaveBeenLastCalledWith(
rpcUrls.value,
);
});

it('sets the provider instance', async () => {
const wallet = 'fake-provider'; // TODO: work-around for horrible mock typing issues.
Object.defineProperty(web3ProviderService, 'createWalletConnectProvider', {
value: vi.fn().mockResolvedValue(wallet),
});
const provider = ref(undefined);
const { connectWalletConnect } = useWallet(provider, ref(undefined), ref({}));

await connectWalletConnect();

expect(provider.value).toBe(wallet);
});

it('sets the connected wallet type', async () => {
const connectedWallet = ref(undefined);
const { connectWalletConnect } = useWallet(ref(undefined), connectedWallet, ref({}));

await connectWalletConnect();

expect(connectedWallet.value).toBe('wallet_connect');
});
});

describe('reconnectToWallet()', () => {
it('can reconnect to MetaMask', async () => {
const provider = ref(undefined);
Expand Down

0 comments on commit f183ae3

Please sign in to comment.