-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a144e1
commit 8931f7d
Showing
1 changed file
with
10 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |