Skip to content

Commit f16dd96

Browse files
chore: fix tests
1 parent 7623c42 commit f16dd96

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

apps/govern/components/Contracts/MyVotingWeight/MyVotingWeight.spec.tsx

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import '@testing-library/jest-dom';
22
import { render, screen } from '@testing-library/react';
33
import { Allocation } from 'types';
4-
import { useAccount } from 'wagmi';
5-
6-
import { useVotingPower } from 'hooks/index';
74

85
import { MyVotingWeight } from './MyVotingWeight';
96

10-
jest.mock('wagmi', () => ({ useAccount: jest.fn() }));
11-
jest.mock('hooks/index', () => ({ useVotingPower: jest.fn() }));
7+
jest.mock('wagmi', () => ({
8+
useAccount: jest.fn().mockReturnValue({ address: '0x1234', isConnected: true }),
9+
}));
10+
jest.mock('hooks/index', () => ({ useVotingPower: jest.fn().mockReturnValue({ data: '75.05' }) }));
1211
jest.mock('store/index', () => ({
1312
useAppSelector: jest.fn().mockReturnValue({
1413
userVotes: {},
@@ -33,13 +32,6 @@ const MyVotingWeightExample = () => {
3332
};
3433

3534
describe('<MyVotingWeight/>', () => {
36-
beforeEach(() => {
37-
jest.clearAllMocks();
38-
39-
(useVotingPower as jest.Mock).mockReturnValue({ data: '75.05' });
40-
(useAccount as jest.Mock).mockReturnValue({ address: '0x1234', isConnected: true });
41-
});
42-
4335
it('should display title and description', () => {
4436
render(<MyVotingWeightExample />);
4537

apps/govern/components/Contracts/MyVotingWeight/Votes.spec.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ import React from 'react';
44

55
import { Votes } from './Votes';
66

7+
jest.mock('wagmi', () => ({
8+
useAccount: jest.fn().mockReturnValue({ address: '0x1234', isConnected: true }),
9+
}));
10+
11+
jest.mock('@wagmi/core', () => ({
12+
readContract: jest.fn(),
13+
readContracts: jest.fn(),
14+
}));
15+
16+
jest.mock('context/Web3ModalProvider', () => ({
17+
queryClient: jest.fn(),
18+
}));
19+
720
jest.mock('store/index', () => ({
21+
useAppDispatch: jest.fn(),
822
useAppSelector: jest.fn().mockReturnValue({
923
lastUserVote: Date.now(),
1024
userVotes: {

apps/govern/jest.setup.js

+4
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ jest.mock('wagmi/chains', () => ({
3333
celo,
3434
mode,
3535
}));
36+
37+
jest.mock('common-util/config/wagmi', () => ({
38+
SUPPORTED_CHAINS: [{ name: 'ethereum', chainId: 1 }],
39+
}));

0 commit comments

Comments
 (0)