Skip to content

Commit e79b399

Browse files
committed
Clean up string formatting, move before/afterEach
Addresses feedback on the PR. Also adddresses (in comment) the fact that we are not handling high number networks in hex, which is what comments in the code of useWallet call for
1 parent cccc3e5 commit e79b399

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

packages/hooks/src/hooks/useWallet.test.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import { useWallet } from './useWallet';
33
import { Provider } from '../Provider';
44
import { renderHook } from '@testing-library/react-hooks';
55

6-
let windowSpy;
6+
describe('useWallet tests', () => {
7+
let windowSpy;
78

8-
beforeEach(() => {
9-
windowSpy = jest.spyOn(window, 'window', 'get');
10-
});
9+
beforeEach(() => {
10+
windowSpy = jest.spyOn(window, 'window', 'get');
11+
});
1112

12-
afterEach(() => {
13-
windowSpy.mockRestore();
14-
});
13+
afterEach(() => {
14+
windowSpy.mockRestore();
15+
});
1516

16-
describe('useWallet tests', () => {
17-
test('should use the wallet', () => {
17+
test('should instantiate for valid input types', () => {
1818
const wrapper = ({ children }) => (
19-
<Provider network={1} infuraId={'abc123'}>
19+
<Provider network={1} infuraId="abc123">
2020
{children}
2121
</Provider>
2222
);
@@ -28,9 +28,9 @@ describe('useWallet tests', () => {
2828

2929
// initially is chainId undefined / requires network per the argument
3030
test('should be able to switch networks', () => {
31-
const testNetwork = 2;
31+
const testNetwork = 111;
3232
const wrapper = ({ children }) => (
33-
<Provider network={testNetwork} infuraId={'abc123'}>
33+
<Provider network={testNetwork} infuraId="abc123">
3434
{children}
3535
</Provider>
3636
);
@@ -53,7 +53,12 @@ describe('useWallet tests', () => {
5353
expect(windowSpy).toHaveBeenCalled();
5454
expect(requestArgs).toStrictEqual({
5555
method: 'wallet_switchEthereumChain',
56+
// this passes (for high number networks)
5657
params: [{ chainId: `0x${testNetwork}` }]
58+
// The test should probably look like this
59+
// if we are in fact converting network numbers to hex
60+
// but fails with the current implementation
61+
// params: [{ chainId: `0x${Number(testNetwork).toString(16)}` }]
5762
});
5863
});
5964
});

0 commit comments

Comments
 (0)