1
1
import React from 'react' ;
2
- import { act , create } from 'react-test-renderer ' ;
2
+ import { render , act } from '@testing-library/ react-native ' ;
3
3
import { NativeModules } from 'react-native' ;
4
4
import {
5
5
ShopifyCheckoutSheetProvider ,
@@ -12,10 +12,8 @@ const config: Configuration = {
12
12
colorScheme : ColorScheme . automatic ,
13
13
} ;
14
14
15
- // Use the shared manual mock. Individual tests can override if needed.
16
15
jest . mock ( 'react-native' ) ;
17
16
18
- // Helper component to test the hook
19
17
const HookTestComponent = ( {
20
18
onHookValue,
21
19
} : {
@@ -26,6 +24,8 @@ const HookTestComponent = ({
26
24
return null ;
27
25
} ;
28
26
27
+ const MockChild = ( ) => null ;
28
+
29
29
describe ( 'ShopifyCheckoutSheetProvider' , ( ) => {
30
30
const TestComponent = ( { children} : { children : React . ReactNode } ) => (
31
31
< ShopifyCheckoutSheetProvider configuration = { config } >
@@ -37,18 +37,22 @@ describe('ShopifyCheckoutSheetProvider', () => {
37
37
jest . clearAllMocks ( ) ;
38
38
} ) ;
39
39
40
- it ( 'renders children correctly ' , ( ) => {
41
- const component = create (
40
+ it ( 'renders without crashing ' , ( ) => {
41
+ const component = render (
42
42
< TestComponent >
43
- < div > Test Child </ div >
43
+ < MockChild / >
44
44
</ TestComponent > ,
45
45
) ;
46
46
47
- expect ( component . toJSON ( ) ) . toBeTruthy ( ) ;
47
+ expect ( component ) . toBeTruthy ( ) ;
48
48
} ) ;
49
49
50
50
it ( 'creates ShopifyCheckoutSheet instance with configuration' , ( ) => {
51
- create ( < TestComponent > test</ TestComponent > ) ;
51
+ render (
52
+ < TestComponent >
53
+ < MockChild />
54
+ </ TestComponent > ,
55
+ ) ;
52
56
53
57
expect (
54
58
NativeModules . ShopifyCheckoutSheetKit . setConfig ,
@@ -58,9 +62,9 @@ describe('ShopifyCheckoutSheetProvider', () => {
58
62
it ( 'creates ShopifyCheckoutSheet instance with features' , ( ) => {
59
63
const features = { handleGeolocationRequests : false } ;
60
64
61
- create (
65
+ render (
62
66
< ShopifyCheckoutSheetProvider features = { features } >
63
- test
67
+ < MockChild />
64
68
</ ShopifyCheckoutSheetProvider > ,
65
69
) ;
66
70
@@ -70,12 +74,20 @@ describe('ShopifyCheckoutSheetProvider', () => {
70
74
} ) ;
71
75
72
76
it ( 'reuses the same instance across re-renders' , ( ) => {
73
- const component = create ( < TestComponent > test</ TestComponent > ) ;
77
+ const { rerender} = render (
78
+ < TestComponent >
79
+ < MockChild />
80
+ </ TestComponent > ,
81
+ ) ;
74
82
75
83
const firstCallCount =
76
84
NativeModules . ShopifyCheckoutSheetKit . setConfig . mock . calls . length ;
77
85
78
- component . update ( < TestComponent > updated</ TestComponent > ) ;
86
+ rerender (
87
+ < TestComponent >
88
+ < MockChild />
89
+ </ TestComponent > ,
90
+ ) ;
79
91
80
92
const secondCallCount =
81
93
NativeModules . ShopifyCheckoutSheetKit . setConfig . mock . calls . length ;
@@ -101,7 +113,7 @@ describe('useShopifyCheckoutSheet', () => {
101
113
hookValue = value ;
102
114
} ;
103
115
104
- create (
116
+ render (
105
117
< Wrapper >
106
118
< HookTestComponent onHookValue = { onHookValue } />
107
119
</ Wrapper > ,
@@ -117,7 +129,7 @@ describe('useShopifyCheckoutSheet', () => {
117
129
hookValue = value ;
118
130
} ;
119
131
120
- create (
132
+ render (
121
133
< Wrapper >
122
134
< HookTestComponent onHookValue = { onHookValue } />
123
135
</ Wrapper > ,
@@ -136,7 +148,7 @@ describe('useShopifyCheckoutSheet', () => {
136
148
hookValue = value ;
137
149
} ;
138
150
139
- create (
151
+ render (
140
152
< Wrapper >
141
153
< HookTestComponent onHookValue = { onHookValue } />
142
154
</ Wrapper > ,
@@ -157,7 +169,7 @@ describe('useShopifyCheckoutSheet', () => {
157
169
hookValue = value ;
158
170
} ;
159
171
160
- create (
172
+ render (
161
173
< Wrapper >
162
174
< HookTestComponent onHookValue = { onHookValue } />
163
175
</ Wrapper > ,
@@ -178,7 +190,7 @@ describe('useShopifyCheckoutSheet', () => {
178
190
hookValue = value ;
179
191
} ;
180
192
181
- create (
193
+ render (
182
194
< Wrapper >
183
195
< HookTestComponent onHookValue = { onHookValue } />
184
196
</ Wrapper > ,
@@ -199,7 +211,7 @@ describe('useShopifyCheckoutSheet', () => {
199
211
hookValue = value ;
200
212
} ;
201
213
202
- create (
214
+ render (
203
215
< Wrapper >
204
216
< HookTestComponent onHookValue = { onHookValue } />
205
217
</ Wrapper > ,
@@ -220,7 +232,7 @@ describe('useShopifyCheckoutSheet', () => {
220
232
hookValue = value ;
221
233
} ;
222
234
223
- create (
235
+ render (
224
236
< Wrapper >
225
237
< HookTestComponent onHookValue = { onHookValue } />
226
238
</ Wrapper > ,
@@ -241,7 +253,7 @@ describe('useShopifyCheckoutSheet', () => {
241
253
hookValue = value ;
242
254
} ;
243
255
244
- create (
256
+ render (
245
257
< Wrapper >
246
258
< HookTestComponent onHookValue = { onHookValue } />
247
259
</ Wrapper > ,
@@ -262,7 +274,7 @@ describe('useShopifyCheckoutSheet', () => {
262
274
263
275
const newConfig = { colorScheme : ColorScheme . light } ;
264
276
265
- create (
277
+ render (
266
278
< Wrapper >
267
279
< HookTestComponent onHookValue = { onHookValue } />
268
280
</ Wrapper > ,
@@ -283,7 +295,7 @@ describe('useShopifyCheckoutSheet', () => {
283
295
hookValue = value ;
284
296
} ;
285
297
286
- create (
298
+ render (
287
299
< Wrapper >
288
300
< HookTestComponent onHookValue = { onHookValue } />
289
301
</ Wrapper > ,
@@ -303,7 +315,7 @@ describe('useShopifyCheckoutSheet', () => {
303
315
hookValue = value ;
304
316
} ;
305
317
306
- create (
318
+ render (
307
319
< Wrapper >
308
320
< HookTestComponent onHookValue = { onHookValue } />
309
321
</ Wrapper > ,
@@ -318,7 +330,7 @@ describe('useShopifyCheckoutSheet', () => {
318
330
hookValue = value ;
319
331
} ;
320
332
321
- create (
333
+ render (
322
334
< Wrapper >
323
335
< HookTestComponent onHookValue = { onHookValue } />
324
336
</ Wrapper > ,
@@ -337,7 +349,7 @@ describe('ShopifyCheckoutSheetContext without provider', () => {
337
349
hookValue = value ;
338
350
} ;
339
351
340
- create ( < HookTestComponent onHookValue = { onHookValue } /> ) ;
352
+ render ( < HookTestComponent onHookValue = { onHookValue } /> ) ;
341
353
342
354
const config = await hookValue . getConfig ( ) ;
343
355
expect ( config ) . toBeUndefined ( ) ;
0 commit comments