From 22688606157f74d84b30b449fa2b99ea022c3794 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 20 Apr 2023 15:30:30 -0700 Subject: [PATCH] test: web3 (#6299) * build: upgrade web3-react@^8.2 * test: web3 * fix: update test name --- src/components/Web3Provider/index.test.tsx | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/components/Web3Provider/index.test.tsx diff --git a/src/components/Web3Provider/index.test.tsx b/src/components/Web3Provider/index.test.tsx new file mode 100644 index 0000000000..9c99477768 --- /dev/null +++ b/src/components/Web3Provider/index.test.tsx @@ -0,0 +1,48 @@ +import { act, render } from '@testing-library/react' +import { initializeConnector, MockEIP1193Provider } from '@web3-react/core' +import { EIP1193 } from '@web3-react/eip1193' +import { Provider as EIP1193Provider } from '@web3-react/types' +import { Connection, ConnectionType } from 'connection' +import useEagerlyConnect from 'hooks/useEagerlyConnect' +import useOrderedConnections from 'hooks/useOrderedConnections' +import { Provider } from 'react-redux' +import store from 'state' +import { mocked } from 'test-utils/mocked' + +import Web3Provider from '.' + +jest.mock('hooks/useEagerlyConnect', () => jest.fn()) +jest.mock('hooks/useOrderedConnections', () => jest.fn()) + +const UI = ( + + {null} + +) + +describe('Web3Provider', () => { + let provider: MockEIP1193Provider & EIP1193Provider + let connection: Connection + + beforeEach(() => { + provider = new MockEIP1193Provider() as MockEIP1193Provider & EIP1193Provider + const [connector, hooks] = initializeConnector((actions) => new EIP1193({ actions, provider })) + connection = { + connector, + hooks, + getName: jest.fn().mockReturnValue('test'), + type: 'INJECTED' as ConnectionType, + shouldDisplay: () => false, + } + mocked(useOrderedConnections).mockReturnValue([connection]) + }) + + it('renders and eagerly connects', async () => { + const result = render(UI) + await act(async () => { + await result + }) + expect(useEagerlyConnect).toHaveBeenCalled() + expect(result).toBeTruthy() + }) +})