@@ -2,14 +2,38 @@ import '@testing-library/jest-dom';
2
2
import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
3
3
import { render , screen , waitFor } from '@testing-library/react' ;
4
4
import { base } from 'viem/chains' ;
5
- import { describe , expect , it , vi } from 'vitest' ;
5
+ import { type Mock , beforeEach , describe , expect , it , vi } from 'vitest' ;
6
6
import { http , WagmiProvider , createConfig } from 'wagmi' ;
7
+ import { useConfig } from 'wagmi' ;
7
8
import { mock } from 'wagmi/connectors' ;
8
9
import { setOnchainKitConfig } from './OnchainKitConfig' ;
9
10
import { OnchainKitProvider } from './OnchainKitProvider' ;
10
11
import { COINBASE_VERIFIED_ACCOUNT_SCHEMA_ID } from './identity/constants' ;
11
12
import type { EASSchemaUid } from './identity/types' ;
12
13
import { useOnchainKit } from './useOnchainKit' ;
14
+ import { useProviderDependencies } from './useProviderDependencies' ;
15
+
16
+ vi . mock ( 'wagmi' , async ( importOriginal ) => {
17
+ const actual = await importOriginal ( ) ;
18
+ return {
19
+ ...actual ,
20
+ useConfig : vi . fn ( ) ,
21
+ } ;
22
+ } ) ;
23
+
24
+ vi . mock ( './useProviderDependencies' , ( ) => ( {
25
+ useProviderDependencies : vi . fn ( ( ) => ( {
26
+ providedWagmiConfig : null ,
27
+ providedQueryClient : null ,
28
+ } ) ) ,
29
+ } ) ) ;
30
+
31
+ vi . mock ( './useProviderDependencies' , ( ) => ( {
32
+ useProviderDependencies : vi . fn ( ( ) => ( {
33
+ providedWagmiConfig : null ,
34
+ providedQueryClient : null ,
35
+ } ) ) ,
36
+ } ) ) ;
13
37
14
38
const queryClient = new QueryClient ( ) ;
15
39
const mockConfig = createConfig ( {
@@ -51,8 +75,17 @@ describe('OnchainKitProvider', () => {
51
75
const apiKey = 'test-api-key' ;
52
76
const paymasterUrl =
53
77
'https://api.developer.coinbase.com/rpc/v1/base/test-api-key' ;
54
- const appLogo = undefined ;
55
- const appName = undefined ;
78
+ const appLogo = '' ;
79
+ const appName = 'Dapp' ;
80
+
81
+ beforeEach ( ( ) => {
82
+ vi . clearAllMocks ( ) ;
83
+ ( useConfig as Mock ) . mockReturnValue ( mockConfig ) ;
84
+ ( useProviderDependencies as Mock ) . mockReturnValue ( {
85
+ providedWagmiConfig : mockConfig ,
86
+ providedQueryClient : queryClient ,
87
+ } ) ;
88
+ } ) ;
56
89
57
90
it ( 'provides the context value correctly' , async ( ) => {
58
91
render (
@@ -71,6 +104,22 @@ describe('OnchainKitProvider', () => {
71
104
} ) ;
72
105
} ) ;
73
106
107
+ it ( 'provides the context value correctly without WagmiProvider' , async ( ) => {
108
+ ( useProviderDependencies as Mock ) . mockReturnValue ( {
109
+ providedWagmiConfig : null ,
110
+ providedQueryClient : null ,
111
+ } ) ;
112
+ render (
113
+ < OnchainKitProvider chain = { base } schemaId = { schemaId } apiKey = { apiKey } >
114
+ < TestComponent />
115
+ </ OnchainKitProvider > ,
116
+ ) ;
117
+ await waitFor ( ( ) => {
118
+ expect ( screen . getByText ( schemaId ) ) . toBeInTheDocument ( ) ;
119
+ expect ( screen . getByText ( apiKey ) ) . toBeInTheDocument ( ) ;
120
+ } ) ;
121
+ } ) ;
122
+
74
123
it ( 'throws an error if schemaId does not meet the required length' , ( ) => {
75
124
expect ( ( ) => {
76
125
render (
0 commit comments