Skip to content

Commit

Permalink
Pass AddressInput test
Browse files Browse the repository at this point in the history
  • Loading branch information
naz3eh committed Dec 6, 2021
1 parent 65fd656 commit a8d6221
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"@web3-ui/hooks": "^0.1.0",
"babel-loader": "^8.2.1",
"classnames": "^2.2.6",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.5.1",
"husky": "^7.0.0",
"identity-obj-proxy": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
import React from 'react';
import { render } from '@testing-library/react';
import { AddressInput } from '.';
import { MockProvider } from 'ethereum-waffle';
import { ethers } from 'ethers';
import 'regenerator-runtime/runtime';

describe('AddressInput', () => {
it('renders', () => {
const provider = new MockProvider();
const [value, setValue] = React.useState('');
const WALLET_ADDRESS = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
const SIGNED_MESSAGE =
'0xa2162955fbfbac44ad895441a3501465861435d6615053a64fc9622d98061f1556e47c6655d0ea02df00ed6f6050298eea381b4c46f8148ecb617b32695bdc451c';

const WINDOW_ETHEREUM = {
isMetaMask: true,
request: async (request: { method: string; params?: Array<unknown> }) => {
// console.log(request.method); to see the different requests made by ethers
if (['eth_accounts', 'eth_requestAccounts'].includes(request.method)) {
return [WALLET_ADDRESS];
} else if (['personal_sign'].includes(request.method)) {
return SIGNED_MESSAGE;
}

throw Error(`Unknown request: ${request.method}`);
},
};

jest.mock('ethers', () => {
const original = jest.requireActual('ethers');
return {
...original,
ethers: {
...original.ethers,
},
};
});

const Component = () => {
const provider = new ethers.providers.Web3Provider(WINDOW_ETHEREUM);
const [value, setValue] = React.useState('');

const { container } = render(
<AddressInput value={value} onChange={(e) => setValue(e)} provider={provider} />
);
return <AddressInput value={value} onChange={(e) => setValue(e)} provider={provider} />;
};

describe('AddressInput', () => {
it('renders AddressInput correctly', () => {
const { container } = render(<Component />);
expect(container);
});
});

0 comments on commit a8d6221

Please sign in to comment.