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,17 @@ 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' ) ;
264278 listener ( { colorScheme : 'dark' } ) ;
265279
266280 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
267281 } ) ;
268282
269- it ( 'the Feedback Widget matches the snapshot with custom light theme' , ( ) => {
283+ it ( 'the Feedback Widget matches the snapshot with custom light theme' , async ( ) => {
270284 mockedIsModalSupported . mockReturnValue ( true ) ;
271285 const { toJSON } = render (
272286 < FeedbackWidgetProvider >
@@ -283,12 +297,14 @@ describe('FeedbackButtonManager', () => {
283297 } ) ;
284298 getClient ( ) ?. addIntegration ( integration ) ;
285299
286- showFeedbackWidget ( ) ;
300+ await act ( async ( ) => {
301+ showFeedbackWidget ( ) ;
302+ } ) ;
287303
288304 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
289305 } ) ;
290306
291- it ( 'the Feedback Widget matches the snapshot with custom dark theme' , ( ) => {
307+ it ( 'the Feedback Widget matches the snapshot with custom dark theme' , async ( ) => {
292308 mockedIsModalSupported . mockReturnValue ( true ) ;
293309 const { toJSON } = render (
294310 < FeedbackWidgetProvider >
@@ -305,12 +321,14 @@ describe('FeedbackButtonManager', () => {
305321 } ) ;
306322 getClient ( ) ?. addIntegration ( integration ) ;
307323
308- showFeedbackWidget ( ) ;
324+ await act ( async ( ) => {
325+ showFeedbackWidget ( ) ;
326+ } ) ;
309327
310328 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
311329 } ) ;
312330
313- it ( 'the Feedback Widget matches the snapshot with system light custom theme' , ( ) => {
331+ it ( 'the Feedback Widget matches the snapshot with system light custom theme' , async ( ) => {
314332 mockedIsModalSupported . mockReturnValue ( true ) ;
315333 const { toJSON } = render (
316334 < FeedbackWidgetProvider >
@@ -329,12 +347,14 @@ describe('FeedbackButtonManager', () => {
329347
330348 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
331349
332- showFeedbackWidget ( ) ;
350+ await act ( async ( ) => {
351+ showFeedbackWidget ( ) ;
352+ } ) ;
333353
334354 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
335355 } ) ;
336356
337- it ( 'the Feedback Widget matches the snapshot with system dark custom theme' , ( ) => {
357+ it ( 'the Feedback Widget matches the snapshot with system dark custom theme' , async ( ) => {
338358 mockedIsModalSupported . mockReturnValue ( true ) ;
339359 const { toJSON } = render (
340360 < FeedbackWidgetProvider >
@@ -353,12 +373,14 @@ describe('FeedbackButtonManager', () => {
353373
354374 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
355375
356- showFeedbackWidget ( ) ;
376+ await act ( async ( ) => {
377+ showFeedbackWidget ( ) ;
378+ } ) ;
357379
358380 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
359381 } ) ;
360382
361- it ( 'the Feedback Button matches the snapshot with default configuration and system light theme' , ( ) => {
383+ it ( 'the Feedback Button matches the snapshot with default configuration and system light theme' , async ( ) => {
362384 mockedIsModalSupported . mockReturnValue ( true ) ;
363385 const { toJSON } = render (
364386 < FeedbackWidgetProvider >
@@ -368,12 +390,14 @@ describe('FeedbackButtonManager', () => {
368390
369391 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
370392
371- showFeedbackButton ( ) ;
393+ await act ( async ( ) => {
394+ showFeedbackWidget ( ) ;
395+ } ) ;
372396
373397 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
374398 } ) ;
375399
376- it ( 'the Feedback Button matches the snapshot with default configuration and system dark theme' , ( ) => {
400+ it ( 'the Feedback Button matches the snapshot with default configuration and system dark theme' , async ( ) => {
377401 mockedIsModalSupported . mockReturnValue ( true ) ;
378402 const { toJSON } = render (
379403 < FeedbackWidgetProvider >
@@ -383,12 +407,14 @@ describe('FeedbackButtonManager', () => {
383407
384408 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
385409
386- showFeedbackButton ( ) ;
410+ await act ( async ( ) => {
411+ showFeedbackWidget ( ) ;
412+ } ) ;
387413
388414 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
389415 } ) ;
390416
391- it ( 'the Feedback Button matches the snapshot with default configuration and dynamically changed theme' , ( ) => {
417+ it ( 'the Feedback Button matches the snapshot with default configuration and dynamically changed theme' , async ( ) => {
392418 const component = (
393419 < FeedbackWidgetProvider >
394420 < Text > App Components</ Text >
@@ -400,15 +426,17 @@ describe('FeedbackButtonManager', () => {
400426
401427 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
402428
403- showFeedbackButton ( ) ;
429+ await act ( async ( ) => {
430+ showFeedbackWidget ( ) ;
431+ } ) ;
404432
405433 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
406434 listener ( { colorScheme : 'dark' } ) ;
407435
408436 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
409437 } ) ;
410438
411- it ( 'the Feedback Button matches the snapshot with custom light theme' , ( ) => {
439+ it ( 'the Feedback Button matches the snapshot with custom light theme' , async ( ) => {
412440 mockedIsModalSupported . mockReturnValue ( true ) ;
413441 const { toJSON } = render (
414442 < FeedbackWidgetProvider >
@@ -425,12 +453,14 @@ describe('FeedbackButtonManager', () => {
425453 } ) ;
426454 getClient ( ) ?. addIntegration ( integration ) ;
427455
428- showFeedbackButton ( ) ;
456+ await act ( async ( ) => {
457+ showFeedbackWidget ( ) ;
458+ } ) ;
429459
430460 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
431461 } ) ;
432462
433- it ( 'the Feedback Button matches the snapshot with custom dark theme' , ( ) => {
463+ it ( 'the Feedback Button matches the snapshot with custom dark theme' , async ( ) => {
434464 mockedIsModalSupported . mockReturnValue ( true ) ;
435465 const { toJSON } = render (
436466 < FeedbackWidgetProvider >
@@ -447,12 +477,14 @@ describe('FeedbackButtonManager', () => {
447477 } ) ;
448478 getClient ( ) ?. addIntegration ( integration ) ;
449479
450- showFeedbackButton ( ) ;
480+ await act ( async ( ) => {
481+ showFeedbackWidget ( ) ;
482+ } ) ;
451483
452484 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
453485 } ) ;
454486
455- it ( 'the Feedback Button matches the snapshot with system light custom theme' , ( ) => {
487+ it ( 'the Feedback Button matches the snapshot with system light custom theme' , async ( ) => {
456488 mockedIsModalSupported . mockReturnValue ( true ) ;
457489 const { toJSON } = render (
458490 < FeedbackWidgetProvider >
@@ -471,12 +503,14 @@ describe('FeedbackButtonManager', () => {
471503
472504 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
473505
474- showFeedbackButton ( ) ;
506+ await act ( async ( ) => {
507+ showFeedbackWidget ( ) ;
508+ } ) ;
475509
476510 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
477511 } ) ;
478512
479- it ( 'the Feedback Button matches the snapshot with system dark custom theme' , ( ) => {
513+ it ( 'the Feedback Button matches the snapshot with system dark custom theme' , async ( ) => {
480514 mockedIsModalSupported . mockReturnValue ( true ) ;
481515 const { toJSON } = render (
482516 < FeedbackWidgetProvider >
@@ -495,7 +529,9 @@ describe('FeedbackButtonManager', () => {
495529
496530 jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
497531
498- showFeedbackButton ( ) ;
532+ await act ( async ( ) => {
533+ showFeedbackWidget ( ) ;
534+ } ) ;
499535
500536 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
501537 } ) ;
0 commit comments