@@ -87,6 +87,7 @@ vi.mock('@solana/wallet-adapter-react', async () => {
87
87
mockSelectWalletFnNotWalletName ( walletName ) ;
88
88
const mockWalletAdapter = {
89
89
adapter : { name : walletName , readyState : WalletReadyState . Installed } ,
90
+ readyState : WalletReadyState . Installed ,
90
91
} ;
91
92
currentWalletRef . value = mockWalletAdapter ;
92
93
setCurrentWallet ( mockWalletAdapter ) ;
@@ -100,18 +101,21 @@ vi.mock('@solana/wallet-adapter-react', async () => {
100
101
name : 'Coinbase Wallet' ,
101
102
readyState : WalletReadyState . Installed ,
102
103
} ,
104
+ readyState : WalletReadyState . Installed ,
103
105
} ,
104
106
{
105
107
adapter : {
106
108
name : 'Phantom Wallet' ,
107
109
readyState : WalletReadyState . Installed ,
108
110
} ,
111
+ readyState : WalletReadyState . Installed ,
109
112
} ,
110
113
{
111
114
adapter : {
112
115
name : 'OKX Wallet' ,
113
116
readyState : WalletReadyState . NotDetected ,
114
117
} ,
118
+ readyState : WalletReadyState . NotDetected ,
115
119
} ,
116
120
] ,
117
121
} ;
@@ -208,11 +212,9 @@ describe('Solana Connect', () => {
208
212
expect ( shownConnectRunDone . textContent ) . toBe ( 'false' ) ;
209
213
210
214
fireEvent . click ( switchWalletBtn ) ;
211
- await vi . waitFor ( ( ) => {
212
- expect ( switchWalletRunned ) . toBeCalled ( ) ;
213
- } ) ;
214
215
215
216
await vi . waitFor ( ( ) => {
217
+ expect ( switchWalletRunned ) . toBeCalled ( ) ;
216
218
expect ( mockWalletChanged ) . toBeCalled ( ) ;
217
219
} ) ;
218
220
@@ -224,25 +226,25 @@ describe('Solana Connect', () => {
224
226
expect ( mockSelectWalletFn ) . toBeCalledTimes ( 3 ) ;
225
227
} ) ;
226
228
227
- await vi . waitFor (
228
- ( ) => {
229
- expect ( connectRunned ) . toBeCalled ( ) ;
230
- expect ( shownConnectRunDone . textContent ) . toBe ( 'true' ) ;
231
- } ,
232
- {
233
- timeout : 5000 ,
234
- } ,
235
- ) ;
229
+ await vi . waitFor ( ( ) => {
230
+ expect ( connectRunned ) . toBeCalled ( ) ;
231
+ expect ( shownConnectRunDone . textContent ) . toBe ( 'true' ) ;
232
+ } ) ;
236
233
} ) ;
237
234
238
235
it ( 'call connect but not provide wallet' , async ( ) => {
239
236
const { useWallet } = await import ( '@solana/wallet-adapter-react' ) ;
240
237
const connectRunned = vi . fn ( ) ;
238
+ const availableWalletFound = vi . fn ( ) ;
241
239
242
240
const CustomConnectBtn : React . FC = ( ) => {
243
- const { connect } = useProvider ( ) ;
241
+ const { connect, availableWallets } = useProvider ( ) ;
244
242
const { connect : connectWallet } = useWallet ( ) ;
245
243
244
+ useEffect ( ( ) => {
245
+ availableWalletFound ( availableWallets ?. length || 0 ) ;
246
+ } , [ availableWallets ] ) ;
247
+
246
248
return (
247
249
< div className = "custom-connectbtn" >
248
250
< button
@@ -255,13 +257,14 @@ describe('Solana Connect', () => {
255
257
>
256
258
Connect
257
259
</ button >
260
+ < div className = "availableWallets" > { availableWallets ?. length || 0 } </ div >
258
261
</ div >
259
262
) ;
260
263
} ;
261
264
262
265
const App = ( ) => {
263
266
return (
264
- < SolanaWeb3ConfigProvider >
267
+ < SolanaWeb3ConfigProvider wallets = { [ ] } >
265
268
< div >
266
269
< div className = "content" > test</ div >
267
270
< CustomConnectBtn />
@@ -272,11 +275,15 @@ describe('Solana Connect', () => {
272
275
273
276
const { selector } = xrender ( App ) ;
274
277
expect ( selector ( '.content' ) ?. textContent ) . toBe ( 'test' ) ;
278
+ expect ( selector ( '.availableWallets' ) ?. textContent ) . toBe ( '0' ) ;
275
279
276
280
const connectBtn = selector ( '.btn-connect' ) ! ;
277
281
expect ( connectBtn ) . not . toBeNull ( ) ;
278
282
279
283
fireEvent . click ( connectBtn ) ;
284
+ await vi . waitFor ( ( ) => {
285
+ expect ( availableWalletFound ) . toBeCalledWith ( 0 ) ;
286
+ } ) ;
280
287
await vi . waitFor ( ( ) => {
281
288
expect ( connectRunned ) . toBeCalled ( ) ;
282
289
expect ( mockSelectWalletFnNotWalletName ) . toBeCalledWith ( null ) ;
@@ -289,7 +296,7 @@ describe('Solana Connect', () => {
289
296
const [ hasExtensionInstalled , setHasExtensionInstalled ] = useState ( false ) ;
290
297
291
298
useEffect ( ( ) => {
292
- availableWallets ! [ 0 ] ?. hasExtensionInstalled ?.( ) . then ( ( v ) => {
299
+ availableWallets ?. [ 0 ] ?. hasExtensionInstalled ?.( ) . then ( ( v ) => {
293
300
setHasExtensionInstalled ( v ) ;
294
301
} ) ;
295
302
} , [ availableWallets ] ) ;
0 commit comments