@@ -13,42 +13,47 @@ afterEach(() => {
13
13
windowSpy . mockRestore ( ) ;
14
14
} ) ;
15
15
16
- test ( 'should use the wallet' , ( ) => {
17
- const wrapper = ( { children } ) => (
18
- < Provider network = { 1 } infuraId = { 'abc123' } >
19
- { children }
20
- </ Provider >
21
- ) ;
22
- const { result } = renderHook ( ( ) => useWallet ( ) , { wrapper } ) ;
23
-
24
- expect ( result . current . connected ) . toBe ( false ) ;
25
- expect ( typeof result . current . connectWallet ) . toBe ( 'function' ) ;
26
- } ) ;
16
+ describe ( 'useWallet tests' , ( ) => {
17
+ test ( 'should use the wallet' , ( ) => {
18
+ const wrapper = ( { children } ) => (
19
+ < Provider network = { 1 } infuraId = { 'abc123' } >
20
+ { children }
21
+ </ Provider >
22
+ ) ;
23
+ const { result } = renderHook ( ( ) => useWallet ( ) , { wrapper } ) ;
24
+
25
+ expect ( result . current . connected ) . toBe ( false ) ;
26
+ expect ( typeof result . current . connectWallet ) . toBe ( 'function' ) ;
27
+ } ) ;
27
28
28
- // initially is chainId undefined / requires network per the argument
29
- test ( 'should be able to switch networks' , ( ) => {
30
- const testNetwork = 2 ;
31
- const wrapper = ( { children } ) => (
32
- < Provider network = { testNetwork } infuraId = { 'abc123' } >
33
- { children }
34
- </ Provider >
35
- ) ;
36
- const { result } = renderHook ( ( ) => useWallet ( ) , { wrapper } ) ;
37
-
38
- let requestArgs ;
39
-
40
- windowSpy . mockImplementation ( ( ) => ( {
41
- ethereum : {
42
- request : arg => {
43
- requestArgs = arg ;
29
+ // initially is chainId undefined / requires network per the argument
30
+ test ( 'should be able to switch networks' , ( ) => {
31
+ const testNetwork = 2 ;
32
+ const wrapper = ( { children } ) => (
33
+ < Provider network = { testNetwork } infuraId = { 'abc123' } >
34
+ { children }
35
+ </ Provider >
36
+ ) ;
37
+ const { result } = renderHook ( ( ) => useWallet ( ) , { wrapper } ) ;
38
+
39
+ let requestArgs ;
40
+
41
+ // hijack the call to window.ethereum.request to capture those args
42
+ // this ensures that we have values in the requestArgs if/when request is called
43
+ // those are checked at the end
44
+ windowSpy . mockImplementation ( ( ) => ( {
45
+ ethereum : {
46
+ request : arg => {
47
+ requestArgs = arg ;
48
+ }
44
49
}
45
- }
46
- } ) ) ;
47
-
48
- result . current . switchToCorrectNetwork ( ) ;
49
- expect ( windowSpy ) . toHaveBeenCalled ( ) ;
50
- expect ( requestArgs ) . toStrictEqual ( {
51
- method : 'wallet_switchEthereumChain' ,
52
- params : [ { chainId : `0x ${ testNetwork } ` } ]
50
+ } ) ) ;
51
+
52
+ result . current . switchToCorrectNetwork ( ) ;
53
+ expect ( windowSpy ) . toHaveBeenCalled ( ) ;
54
+ expect ( requestArgs ) . toStrictEqual ( {
55
+ method : 'wallet_switchEthereumChain' ,
56
+ params : [ { chainId : `0x ${ testNetwork } ` } ]
57
+ } ) ;
53
58
} ) ;
54
59
} ) ;
0 commit comments