Skip to content

Commit

Permalink
test(web3js): fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonstudio committed May 14, 2024
1 parent 1a144e1 commit 8931f7d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/eth-web3js/src/hooks/use-web3js.test.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { Mainnet } from '@ant-design/web3-assets';
import { render } from '@testing-library/react';
import { describe, expect, test } from 'vitest';
import Web3 from 'web3';
import { describe, expect, test, vi } from 'vitest';

import { MetaMask } from '../wallets';
import { EthWeb3jsConfigProvider } from '../web3js-provider';
import { useWeb3js } from './use-web3js';

describe('useWeb3js', async () => {
test('basic usage', async () => {
const CustomConnector: React.FC = () => {
const web3 = useWeb3js();
expect(web3).instanceOf(Web3);
return null;
useWeb3js();
return <div className="text">web3js</div>;
};

const App = () => (
<EthWeb3jsConfigProvider>
<EthWeb3jsConfigProvider wallets={[MetaMask()]} chains={[Mainnet]}>
<CustomConnector />
</EthWeb3jsConfigProvider>
);

render(<App />);
const { baseElement } = render(<App />);
await vi.waitFor(() => {
expect(baseElement.querySelector('.text')?.textContent).toBe('web3js');
});
});
});

0 comments on commit 8931f7d

Please sign in to comment.