11import { debug , getClient , setCurrentClient } from '@sentry/core' ;
2- import { render } from '@testing-library/react-native' ;
2+ import { act , render , waitFor } from '@testing-library/react-native' ;
33import * as React from 'react' ;
44import { Appearance , Text } from 'react-native' ;
55import { defaultConfiguration } from '../../src/js/feedback/defaults' ;
@@ -33,7 +33,7 @@ describe('FeedbackWidgetManager', () => {
3333 resetFeedbackWidgetManager ( ) ;
3434 } ) ;
3535
36- it ( 'showFeedbackWidget displays the form when FeedbackWidgetProvider is used' , ( ) => {
36+ it ( 'showFeedbackWidget displays the form when FeedbackWidgetProvider is used' , async ( ) => {
3737 mockedIsModalSupported . mockReturnValue ( true ) ;
3838 const { getByText, getByTestId } = render (
3939 < FeedbackWidgetProvider >
@@ -43,7 +43,9 @@ describe('FeedbackWidgetManager', () => {
4343
4444 showFeedbackWidget ( ) ;
4545
46- expect ( getByTestId ( 'feedback-form-modal' ) ) . toBeTruthy ( ) ;
46+ await waitFor ( ( ) => {
47+ expect ( getByTestId ( 'feedback-form-modal' ) ) . toBeTruthy ( ) ;
48+ } ) ;
4749 expect ( getByText ( 'App Components' ) ) . toBeTruthy ( ) ;
4850 } ) ;
4951
@@ -70,7 +72,7 @@ describe('FeedbackWidgetManager', () => {
7072 } ) . not . toThrow ( ) ;
7173 } ) ;
7274
73- it ( 'showFeedbackWidget displays the form with the feedbackIntegration options' , ( ) => {
75+ it ( 'showFeedbackWidget displays the form with the feedbackIntegration options' , async ( ) => {
7476 mockedIsModalSupported . mockReturnValue ( true ) ;
7577 const { getByPlaceholderText, getByText } = render (
7678 < FeedbackWidgetProvider >
@@ -86,11 +88,13 @@ describe('FeedbackWidgetManager', () => {
8688
8789 showFeedbackWidget ( ) ;
8890
89- expect ( getByPlaceholderText ( 'Custom Message Placeholder' ) ) . toBeTruthy ( ) ;
91+ await waitFor ( ( ) => {
92+ expect ( getByPlaceholderText ( 'Custom Message Placeholder' ) ) . toBeTruthy ( ) ;
93+ } ) ;
9094 expect ( getByText ( 'Custom Submit Button' ) ) . toBeTruthy ( ) ;
9195 } ) ;
9296
93- it ( 'showFeedbackWidget displays the form with the feedbackIntegration options merged with the defaults' , ( ) => {
97+ it ( 'showFeedbackWidget displays the form with the feedbackIntegration options merged with the defaults' , async ( ) => {
9498 mockedIsModalSupported . mockReturnValue ( true ) ;
9599 const { getByPlaceholderText, getByText, queryByText } = render (
96100 < FeedbackWidgetProvider >
@@ -105,8 +109,10 @@ describe('FeedbackWidgetManager', () => {
105109
106110 showFeedbackWidget ( ) ;
107111
108- expect ( queryByText ( defaultConfiguration . submitButtonLabel ) ) . toBeFalsy ( ) ; // overridden value
109- expect ( getByText ( 'Custom Submit Button' ) ) . toBeTruthy ( ) ; // overridden value
112+ await waitFor ( ( ) => {
113+ expect ( queryByText ( defaultConfiguration . submitButtonLabel ) ) . toBeFalsy ( ) ; // overridden value
114+ expect ( getByText ( 'Custom Submit Button' ) ) . toBeTruthy ( ) ; // overridden value
115+ } ) ;
110116 expect ( getByPlaceholderText ( defaultConfiguration . messagePlaceholder ) ) . toBeTruthy ( ) ; // default configuration value
111117 } ) ;
112118
@@ -161,7 +167,7 @@ describe('FeedbackButtonManager', () => {
161167 } ) ;
162168 } ) ;
163169
164- it ( 'showFeedbackButton displays the button when FeedbackWidgetProvider is used' , ( ) => {
170+ it ( 'showFeedbackButton displays the button when FeedbackWidgetProvider is used' , async ( ) => {
165171 const { getByText } = render (
166172 < FeedbackWidgetProvider >
167173 < Text > App Components</ Text >
@@ -170,7 +176,9 @@ describe('FeedbackButtonManager', () => {
170176
171177 showFeedbackButton ( ) ;
172178
173- expect ( getByText ( 'Report a Bug' ) ) . toBeTruthy ( ) ;
179+ await waitFor ( ( ) => {
180+ expect ( getByText ( 'Report a Bug' ) ) . toBeTruthy ( ) ;
181+ } )
174182 } ) ;
175183
176184 it ( 'hideFeedbackButton hides the button' , ( ) => {
@@ -216,7 +224,7 @@ describe('FeedbackButtonManager', () => {
216224 expect ( getClient ( ) . getIntegrationByName ( AUTO_INJECT_FEEDBACK_BUTTON_INTEGRATION_NAME ) ) . toBeDefined ( ) ;
217225 } ) ;
218226
219- it ( 'the Feedback Widget matches the snapshot with default configuration and system light theme' , ( ) => {
227+ it ( 'the Feedback Widget matches the snapshot with default configuration and system light theme' , async ( ) => {
220228 mockedIsModalSupported . mockReturnValue ( true ) ;
221229 const { toJSON } = render (
222230 < FeedbackWidgetProvider >
@@ -226,12 +234,14 @@ describe('FeedbackButtonManager', () => {
226234
227235 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
228236
229- showFeedbackWidget ( ) ;
237+ await act ( async ( ) => {
238+ showFeedbackWidget ( ) ;
239+ } ) ;
230240
231241 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
232242 } ) ;
233243
234- it ( 'the Feedback Widget matches the snapshot with default configuration and system dark theme' , ( ) => {
244+ it ( 'the Feedback Widget matches the snapshot with default configuration and system dark theme' , async ( ) => {
235245 mockedIsModalSupported . mockReturnValue ( true ) ;
236246 const { toJSON } = render (
237247 < FeedbackWidgetProvider >
@@ -241,12 +251,14 @@ describe('FeedbackButtonManager', () => {
241251
242252 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
243253
244- showFeedbackWidget ( ) ;
254+ await act ( async ( ) => {
255+ showFeedbackWidget ( ) ;
256+ } ) ;
245257
246258 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
247259 } ) ;
248260
249- it ( 'the Feedback Widget matches the snapshot with default configuration and dynamically changed theme' , ( ) => {
261+ it ( 'the Feedback Widget matches the snapshot with default configuration and dynamically changed theme' , async ( ) => {
250262 const component = (
251263 < FeedbackWidgetProvider >
252264 < Text > App Components</ Text >
@@ -258,15 +270,19 @@ describe('FeedbackButtonManager', () => {
258270
259271 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
260272
261- showFeedbackWidget ( ) ;
273+ await act ( async ( ) => {
274+ showFeedbackWidget ( ) ;
275+ } ) ;
262276
263277 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
264- listener ( { colorScheme : 'dark' } ) ;
278+ await act ( async ( ) => {
279+ listener ( { colorScheme : 'dark' } ) ;
280+ } )
265281
266282 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
267283 } ) ;
268284
269- it ( 'the Feedback Widget matches the snapshot with custom light theme' , ( ) => {
285+ it ( 'the Feedback Widget matches the snapshot with custom light theme' , async ( ) => {
270286 mockedIsModalSupported . mockReturnValue ( true ) ;
271287 const { toJSON } = render (
272288 < FeedbackWidgetProvider >
@@ -283,12 +299,14 @@ describe('FeedbackButtonManager', () => {
283299 } ) ;
284300 getClient ( ) ?. addIntegration ( integration ) ;
285301
286- showFeedbackWidget ( ) ;
302+ await act ( async ( ) => {
303+ showFeedbackWidget ( ) ;
304+ } ) ;
287305
288306 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
289307 } ) ;
290308
291- it ( 'the Feedback Widget matches the snapshot with custom dark theme' , ( ) => {
309+ it ( 'the Feedback Widget matches the snapshot with custom dark theme' , async ( ) => {
292310 mockedIsModalSupported . mockReturnValue ( true ) ;
293311 const { toJSON } = render (
294312 < FeedbackWidgetProvider >
@@ -305,12 +323,14 @@ describe('FeedbackButtonManager', () => {
305323 } ) ;
306324 getClient ( ) ?. addIntegration ( integration ) ;
307325
308- showFeedbackWidget ( ) ;
326+ await act ( async ( ) => {
327+ showFeedbackWidget ( ) ;
328+ } ) ;
309329
310330 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
311331 } ) ;
312332
313- it ( 'the Feedback Widget matches the snapshot with system light custom theme' , ( ) => {
333+ it ( 'the Feedback Widget matches the snapshot with system light custom theme' , async ( ) => {
314334 mockedIsModalSupported . mockReturnValue ( true ) ;
315335 const { toJSON } = render (
316336 < FeedbackWidgetProvider >
@@ -329,12 +349,14 @@ describe('FeedbackButtonManager', () => {
329349
330350 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
331351
332- showFeedbackWidget ( ) ;
352+ await act ( async ( ) => {
353+ showFeedbackWidget ( ) ;
354+ } ) ;
333355
334356 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
335357 } ) ;
336358
337- it ( 'the Feedback Widget matches the snapshot with system dark custom theme' , ( ) => {
359+ it ( 'the Feedback Widget matches the snapshot with system dark custom theme' , async ( ) => {
338360 mockedIsModalSupported . mockReturnValue ( true ) ;
339361 const { toJSON } = render (
340362 < FeedbackWidgetProvider >
@@ -353,12 +375,14 @@ describe('FeedbackButtonManager', () => {
353375
354376 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
355377
356- showFeedbackWidget ( ) ;
378+ await act ( async ( ) => {
379+ showFeedbackWidget ( ) ;
380+ } ) ;
357381
358382 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
359383 } ) ;
360384
361- it ( 'the Feedback Button matches the snapshot with default configuration and system light theme' , ( ) => {
385+ it ( 'the Feedback Button matches the snapshot with default configuration and system light theme' , async ( ) => {
362386 mockedIsModalSupported . mockReturnValue ( true ) ;
363387 const { toJSON } = render (
364388 < FeedbackWidgetProvider >
@@ -368,12 +392,14 @@ describe('FeedbackButtonManager', () => {
368392
369393 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
370394
371- showFeedbackButton ( ) ;
395+ await act ( async ( ) => {
396+ showFeedbackButton ( ) ;
397+ } )
372398
373399 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
374400 } ) ;
375401
376- it ( 'the Feedback Button matches the snapshot with default configuration and system dark theme' , ( ) => {
402+ it ( 'the Feedback Button matches the snapshot with default configuration and system dark theme' , async ( ) => {
377403 mockedIsModalSupported . mockReturnValue ( true ) ;
378404 const { toJSON } = render (
379405 < FeedbackWidgetProvider >
@@ -383,12 +409,14 @@ describe('FeedbackButtonManager', () => {
383409
384410 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
385411
386- showFeedbackButton ( ) ;
412+ await act ( async ( ) => {
413+ showFeedbackButton ( ) ;
414+ } ) ;
387415
388416 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
389417 } ) ;
390418
391- it ( 'the Feedback Button matches the snapshot with default configuration and dynamically changed theme' , ( ) => {
419+ it ( 'the Feedback Button matches the snapshot with default configuration and dynamically changed theme' , async ( ) => {
392420 const component = (
393421 < FeedbackWidgetProvider >
394422 < Text > App Components</ Text >
@@ -400,15 +428,19 @@ describe('FeedbackButtonManager', () => {
400428
401429 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
402430
403- showFeedbackButton ( ) ;
431+ await act ( async ( ) => {
432+ showFeedbackButton ( ) ;
433+ } ) ;
404434
405435 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
406- listener ( { colorScheme : 'dark' } ) ;
436+ await act ( async ( ) => {
437+ listener ( { colorScheme : 'dark' } ) ;
438+ } ) ;
407439
408440 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
409441 } ) ;
410442
411- it ( 'the Feedback Button matches the snapshot with custom light theme' , ( ) => {
443+ it ( 'the Feedback Button matches the snapshot with custom light theme' , async ( ) => {
412444 mockedIsModalSupported . mockReturnValue ( true ) ;
413445 const { toJSON } = render (
414446 < FeedbackWidgetProvider >
@@ -425,12 +457,14 @@ describe('FeedbackButtonManager', () => {
425457 } ) ;
426458 getClient ( ) ?. addIntegration ( integration ) ;
427459
428- showFeedbackButton ( ) ;
460+ await act ( async ( ) => {
461+ showFeedbackButton ( ) ;
462+ } ) ;
429463
430464 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
431465 } ) ;
432466
433- it ( 'the Feedback Button matches the snapshot with custom dark theme' , ( ) => {
467+ it ( 'the Feedback Button matches the snapshot with custom dark theme' , async ( ) => {
434468 mockedIsModalSupported . mockReturnValue ( true ) ;
435469 const { toJSON } = render (
436470 < FeedbackWidgetProvider >
@@ -447,12 +481,14 @@ describe('FeedbackButtonManager', () => {
447481 } ) ;
448482 getClient ( ) ?. addIntegration ( integration ) ;
449483
450- showFeedbackButton ( ) ;
484+ await act ( async ( ) => {
485+ showFeedbackButton ( ) ;
486+ } ) ;
451487
452488 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
453489 } ) ;
454490
455- it ( 'the Feedback Button matches the snapshot with system light custom theme' , ( ) => {
491+ it ( 'the Feedback Button matches the snapshot with system light custom theme' , async ( ) => {
456492 mockedIsModalSupported . mockReturnValue ( true ) ;
457493 const { toJSON } = render (
458494 < FeedbackWidgetProvider >
@@ -471,12 +507,14 @@ describe('FeedbackButtonManager', () => {
471507
472508 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
473509
474- showFeedbackButton ( ) ;
510+ await act ( async ( ) => {
511+ showFeedbackButton ( ) ;
512+ } ) ;
475513
476514 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
477515 } ) ;
478516
479- it ( 'the Feedback Button matches the snapshot with system dark custom theme' , ( ) => {
517+ it ( 'the Feedback Button matches the snapshot with system dark custom theme' , async ( ) => {
480518 mockedIsModalSupported . mockReturnValue ( true ) ;
481519 const { toJSON } = render (
482520 < FeedbackWidgetProvider >
@@ -495,7 +533,9 @@ describe('FeedbackButtonManager', () => {
495533
496534 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
497535
498- showFeedbackButton ( ) ;
536+ await act ( async ( ) => {
537+ showFeedbackButton ( ) ;
538+ } ) ;
499539
500540 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
501541 } ) ;
0 commit comments