Wrap Web3Container with act
This commit is contained in:
parent
e3a1142579
commit
6e6a79d8e3
@ -1,4 +1,4 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { fireEvent, render, screen, act } from '@testing-library/react';
|
||||
import { Web3Container } from './web3-container';
|
||||
|
||||
const defaultHookValue = {
|
||||
@ -17,13 +17,15 @@ jest.mock('@web3-react/core', () => {
|
||||
};
|
||||
});
|
||||
|
||||
test('Prompt to connect opens dialog', () => {
|
||||
test('Prompt to connect opens dialog', async () => {
|
||||
mockHookValue = defaultHookValue;
|
||||
render(
|
||||
<Web3Container>
|
||||
<div>Child</div>
|
||||
</Web3Container>
|
||||
);
|
||||
await act(async () => {
|
||||
render(
|
||||
<Web3Container>
|
||||
<div>Child</div>
|
||||
</Web3Container>
|
||||
);
|
||||
});
|
||||
|
||||
expect(screen.queryByText('Child')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('web3-connector-list')).not.toBeInTheDocument();
|
||||
@ -32,33 +34,35 @@ test('Prompt to connect opens dialog', () => {
|
||||
expect(screen.getByTestId('web3-connector-list')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Error message is shown', () => {
|
||||
test('Error message is shown', async () => {
|
||||
const message = 'Opps! An error';
|
||||
mockHookValue = { ...defaultHookValue, error: new Error(message) };
|
||||
|
||||
render(
|
||||
<Web3Container>
|
||||
<div>Child</div>
|
||||
</Web3Container>
|
||||
);
|
||||
await act(async () => {
|
||||
render(
|
||||
<Web3Container>
|
||||
<div>Child</div>
|
||||
</Web3Container>
|
||||
);
|
||||
});
|
||||
|
||||
expect(screen.queryByText('Child')).not.toBeInTheDocument();
|
||||
expect(screen.getByText(`Something went wrong: ${message}`));
|
||||
});
|
||||
|
||||
test('Chain id matches app configuration', () => {
|
||||
test('Chain id matches app configuration', async () => {
|
||||
const expectedChainId = 4;
|
||||
mockHookValue = {
|
||||
...defaultHookValue,
|
||||
isActive: true,
|
||||
chainId: expectedChainId,
|
||||
};
|
||||
|
||||
render(
|
||||
<Web3Container>
|
||||
<div>Child</div>
|
||||
</Web3Container>
|
||||
);
|
||||
await act(async () => {
|
||||
render(
|
||||
<Web3Container>
|
||||
<div>Child</div>
|
||||
</Web3Container>
|
||||
);
|
||||
});
|
||||
|
||||
expect(screen.queryByText('Child')).not.toBeInTheDocument();
|
||||
expect(screen.getByText(`This app only works on chain ID: 3`));
|
||||
|
Loading…
Reference in New Issue
Block a user