soroswap / frontend

Soroswap.Finance Frontend Repo
https://soroswap.finance
MIT License
4 stars 9 forks source link

[Cypress] try to mock soroban-react functions to test web3 features #442

Closed chopan123 closed 1 month ago

chopan123 commented 2 months ago

Check: cypress/e2e/connectWallet.test.ts for example to log and mock some functions,

The intention of that test is to connect wallet, but it is not working. you can uncomment // cy.contains('Public Key: publicKey') to see screenshots of the browser and logs on logs/

I am not quite sure about why I am not getting into the try nor the catch block of the following function:

  const connectWallet = async (wallet: Connector) => {
    const connect = setActiveConnectorAndConnect && setActiveConnectorAndConnect(wallet);
    try {
      await connect;
      setConnectWalletModalOpen(false);
    } catch (err) {
      const errorMessage = `${err}`;
      if (errorMessage.includes(`Error: Wallet hasn't been set upp`)) {
        onError(`Error: Wallet hasn't been set up. Please set up your xBull wallet.`);
      } else {
        onError('Something went wrong. Please try again.');
      }
    }
  };

Explain to the team how to do it

abstract829 commented 2 months ago

we can not mock component functions on e2e tests, we should use component testing for that

I created a component test that mount the app in the swap page and do the wallet connection

How to run:

-npx cypress open -Select component testing -Start component testing in chrome -Select app.test.tsx

That should run a test in swap page connecting a wallet