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 ,
@@ -26,6 +26,11 @@ const HookTestComponent = ({
26
26
return null ;
27
27
} ;
28
28
29
+ /**
30
+ * Dummy child component to avoid rendering raw strings with React Native renderer
31
+ */
32
+ const MockChild = ( ) => null ;
33
+
29
34
describe ( 'ShopifyCheckoutSheetProvider' , ( ) => {
30
35
const TestComponent = ( { children} : { children : React . ReactNode } ) => (
31
36
< ShopifyCheckoutSheetProvider configuration = { config } >
@@ -37,18 +42,22 @@ describe('ShopifyCheckoutSheetProvider', () => {
37
42
jest . clearAllMocks ( ) ;
38
43
} ) ;
39
44
40
- it ( 'renders children correctly ' , ( ) => {
41
- const component = create (
45
+ it ( 'renders without crashing ' , ( ) => {
46
+ const component = render (
42
47
< TestComponent >
43
- < div > Test Child </ div >
48
+ < MockChild / >
44
49
</ TestComponent > ,
45
50
) ;
46
51
47
- expect ( component . toJSON ( ) ) . toBeTruthy ( ) ;
52
+ expect ( component ) . toBeTruthy ( ) ;
48
53
} ) ;
49
54
50
55
it ( 'creates ShopifyCheckoutSheet instance with configuration' , ( ) => {
51
- create ( < TestComponent > test</ TestComponent > ) ;
56
+ render (
57
+ < TestComponent >
58
+ < MockChild />
59
+ </ TestComponent > ,
60
+ ) ;
52
61
53
62
expect (
54
63
NativeModules . ShopifyCheckoutSheetKit . setConfig ,
@@ -58,9 +67,9 @@ describe('ShopifyCheckoutSheetProvider', () => {
58
67
it ( 'creates ShopifyCheckoutSheet instance with features' , ( ) => {
59
68
const features = { handleGeolocationRequests : false } ;
60
69
61
- create (
70
+ render (
62
71
< ShopifyCheckoutSheetProvider features = { features } >
63
- test
72
+ < MockChild />
64
73
</ ShopifyCheckoutSheetProvider > ,
65
74
) ;
66
75
@@ -70,12 +79,20 @@ describe('ShopifyCheckoutSheetProvider', () => {
70
79
} ) ;
71
80
72
81
it ( 'reuses the same instance across re-renders' , ( ) => {
73
- const component = create ( < TestComponent > test</ TestComponent > ) ;
82
+ const { rerender} = render (
83
+ < TestComponent >
84
+ < MockChild />
85
+ </ TestComponent > ,
86
+ ) ;
74
87
75
88
const firstCallCount =
76
89
NativeModules . ShopifyCheckoutSheetKit . setConfig . mock . calls . length ;
77
90
78
- component . update ( < TestComponent > updated</ TestComponent > ) ;
91
+ rerender (
92
+ < TestComponent >
93
+ < MockChild />
94
+ </ TestComponent > ,
95
+ ) ;
79
96
80
97
const secondCallCount =
81
98
NativeModules . ShopifyCheckoutSheetKit . setConfig . mock . calls . length ;
@@ -101,7 +118,7 @@ describe('useShopifyCheckoutSheet', () => {
101
118
hookValue = value ;
102
119
} ;
103
120
104
- create (
121
+ render (
105
122
< Wrapper >
106
123
< HookTestComponent onHookValue = { onHookValue } />
107
124
</ Wrapper > ,
@@ -117,7 +134,7 @@ describe('useShopifyCheckoutSheet', () => {
117
134
hookValue = value ;
118
135
} ;
119
136
120
- create (
137
+ render (
121
138
< Wrapper >
122
139
< HookTestComponent onHookValue = { onHookValue } />
123
140
</ Wrapper > ,
@@ -136,7 +153,7 @@ describe('useShopifyCheckoutSheet', () => {
136
153
hookValue = value ;
137
154
} ;
138
155
139
- create (
156
+ render (
140
157
< Wrapper >
141
158
< HookTestComponent onHookValue = { onHookValue } />
142
159
</ Wrapper > ,
@@ -157,7 +174,7 @@ describe('useShopifyCheckoutSheet', () => {
157
174
hookValue = value ;
158
175
} ;
159
176
160
- create (
177
+ render (
161
178
< Wrapper >
162
179
< HookTestComponent onHookValue = { onHookValue } />
163
180
</ Wrapper > ,
@@ -178,7 +195,7 @@ describe('useShopifyCheckoutSheet', () => {
178
195
hookValue = value ;
179
196
} ;
180
197
181
- create (
198
+ render (
182
199
< Wrapper >
183
200
< HookTestComponent onHookValue = { onHookValue } />
184
201
</ Wrapper > ,
@@ -199,7 +216,7 @@ describe('useShopifyCheckoutSheet', () => {
199
216
hookValue = value ;
200
217
} ;
201
218
202
- create (
219
+ render (
203
220
< Wrapper >
204
221
< HookTestComponent onHookValue = { onHookValue } />
205
222
</ Wrapper > ,
@@ -220,7 +237,7 @@ describe('useShopifyCheckoutSheet', () => {
220
237
hookValue = value ;
221
238
} ;
222
239
223
- create (
240
+ render (
224
241
< Wrapper >
225
242
< HookTestComponent onHookValue = { onHookValue } />
226
243
</ Wrapper > ,
@@ -241,7 +258,7 @@ describe('useShopifyCheckoutSheet', () => {
241
258
hookValue = value ;
242
259
} ;
243
260
244
- create (
261
+ render (
245
262
< Wrapper >
246
263
< HookTestComponent onHookValue = { onHookValue } />
247
264
</ Wrapper > ,
@@ -262,7 +279,7 @@ describe('useShopifyCheckoutSheet', () => {
262
279
263
280
const newConfig = { colorScheme : ColorScheme . light } ;
264
281
265
- create (
282
+ render (
266
283
< Wrapper >
267
284
< HookTestComponent onHookValue = { onHookValue } />
268
285
</ Wrapper > ,
@@ -283,7 +300,7 @@ describe('useShopifyCheckoutSheet', () => {
283
300
hookValue = value ;
284
301
} ;
285
302
286
- create (
303
+ render (
287
304
< Wrapper >
288
305
< HookTestComponent onHookValue = { onHookValue } />
289
306
</ Wrapper > ,
@@ -303,7 +320,7 @@ describe('useShopifyCheckoutSheet', () => {
303
320
hookValue = value ;
304
321
} ;
305
322
306
- create (
323
+ render (
307
324
< Wrapper >
308
325
< HookTestComponent onHookValue = { onHookValue } />
309
326
</ Wrapper > ,
@@ -318,7 +335,7 @@ describe('useShopifyCheckoutSheet', () => {
318
335
hookValue = value ;
319
336
} ;
320
337
321
- create (
338
+ render (
322
339
< Wrapper >
323
340
< HookTestComponent onHookValue = { onHookValue } />
324
341
</ Wrapper > ,
@@ -337,7 +354,7 @@ describe('ShopifyCheckoutSheetContext without provider', () => {
337
354
hookValue = value ;
338
355
} ;
339
356
340
- create ( < HookTestComponent onHookValue = { onHookValue } /> ) ;
357
+ render ( < HookTestComponent onHookValue = { onHookValue } /> ) ;
341
358
342
359
const config = await hookValue . getConfig ( ) ;
343
360
expect ( config ) . toBeUndefined ( ) ;
0 commit comments