Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web3-Mock doesn't work with a real application (MetaMask/test-dapp) #34

Open
matstyler opened this issue Jun 2, 2024 · 1 comment
Open

Comments

@matstyler
Copy link

matstyler commented Jun 2, 2024

I was able to setup Web3-Mock using Playwright but I cannot use it properly with Cypress. Lets say I have a very simple use case. I mock the metamask wallet and then I want to test that mock using @metamask/test-dapp. Nothing is working as expected and I get provider errors:

Screenshot 2024-06-02 at 15 59 22

The thing is I am able to use window object in the e2e test code but this is not what I need. I want the mock working in e2e manual test - for example by clicking on the "ETH ACCOUNTS" button.

Screenshot 2024-06-02 at 16 01 00

My code for this simple example:

const accounts = ['0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045']

beforeEach(()=>{
  mock({ blockchain: 'ethereum', accounts: { return: accounts }, wallet: 'metamask' })
})

it("should mock account", () => {
cy.visit("http://localhost:9999");

cy.get("#getAccounts").click();
})
@matstyler matstyler changed the title Web3-Mock doesn't work with the @metamask/test-dapp Web3-Mock doesn't work with a real application Jun 2, 2024
@matstyler matstyler changed the title Web3-Mock doesn't work with a real application Web3-Mock doesn't work with a real application (MetaMask/test-dapp) Jun 2, 2024
@0xNe0x1
Copy link
Contributor

0xNe0x1 commented Sep 12, 2024

If you call visit after mock the entire javascript state gets flushed. Meaning the entire mock will be deleted.

Try

cy.visit("http://localhost:9999");
mock();
cy.get("#getAccounts").click();

or move the visit into the before. Just make sure you call mock everytime you flush the windows JS state (e.g. when calling visit).

@DePayFi DePayFi deleted a comment from johanneskares Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants