Skip to content

Commit af08da8

Browse files
committed
Refactor test to not rely on lodash
1 parent 02af22b commit af08da8

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

packages/queries/__tests__/.eslintrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"rules": {
3+
"no-console": "off",
4+
"@typescript-eslint/no-var-requires": "off",
5+
"@typescript-eslint/no-non-null-assertion": "off"
6+
}
7+
}

packages/queries/__tests__/network.test.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { NetworkIdByName } from '@synthetixio/contracts-interface';
22
import { wei } from '@synthetixio/wei';
33
import { renderHook } from '@testing-library/react-hooks';
44
import { BigNumber } from '@ethersproject/bignumber';
5-
import { JsonRpcProvider } from '@ethersproject/providers';
6-
import { set } from 'lodash';
75
import useEthGasPriceQuery, { computeGasFee } from '../src/queries/network/useEthGasPriceQuery';
86
import { getFakeQueryContext, getWrapper } from '../testUtils';
97

@@ -15,9 +13,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => {
1513
// set to 0.015 gwei
1614
const defaultGasPrice = wei(0.015, 9).toBN();
1715
//mock provider
18-
set(ctx.provider as JsonRpcProvider, 'getGasPrice', async () =>
19-
Promise.resolve(defaultGasPrice)
20-
);
16+
ctx.provider!.getGasPrice = jest.fn().mockResolvedValue(defaultGasPrice);
2117

2218
const { result, waitFor } = renderHook(() => useEthGasPriceQuery(ctx), { wrapper });
2319

@@ -37,9 +33,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => {
3733
// set to 0.015 gwei
3834
const defaultGasPrice = wei(0.015, 9).toBN();
3935
//mock provider
40-
set(ctx.provider as JsonRpcProvider, 'getGasPrice', async () =>
41-
Promise.resolve(defaultGasPrice)
42-
);
36+
ctx.provider!.getGasPrice = jest.fn().mockResolvedValue(defaultGasPrice);
4337

4438
const { result, waitFor } = renderHook(() => useEthGasPriceQuery(ctx), { wrapper });
4539

@@ -58,10 +52,8 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => {
5852
// set to 0.015 gwei
5953
const defaultGasPrice = wei(0.015, 9).toBN();
6054
//mock provider
61-
set(ctx.provider as ethers.providers.JsonRpcProvider, 'getGasPrice', async () =>
62-
Promise.resolve(defaultGasPrice)
63-
);
6455

56+
ctx.provider!.getGasPrice = jest.fn().mockResolvedValue(defaultGasPrice);
6557
const { result, waitFor } = renderHook(() => useEthGasPriceQuery(ctx), { wrapper });
6658

6759
await waitFor(() => result.current.isSuccess);
@@ -109,9 +101,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => {
109101
// set to 100 gwei
110102
const defaultBaseFeePerGas = wei(100, 9).toBN();
111103
//mock provider
112-
set(ctx.provider as JsonRpcProvider, 'getBlock', async () =>
113-
Promise.resolve({ baseFeePerGas: defaultBaseFeePerGas })
114-
);
104+
ctx.provider!.getBlock = jest.fn().mockResolvedValue({ baseFeePerGas: defaultBaseFeePerGas });
115105

116106
const { result, waitFor } = renderHook(() => useEthGasPriceQuery(ctx), { wrapper });
117107

0 commit comments

Comments
 (0)