@@ -4,7 +4,7 @@ import { rejectedSyncPromise, SentryError } from '@sentry/utils';
44import * as RN from 'react-native' ;
55
66import { ReactNativeClient } from '../src/js/client' ;
7- import { ReactNativeClientOptions , ReactNativeOptions } from '../src/js/options' ;
7+ import { ReactNativeClientOptions } from '../src/js/options' ;
88import { NativeTransport } from '../src/js/transports/native' ;
99import { SDK_NAME , SDK_PACKAGE_NAME , SDK_VERSION } from '../src/js/version' ;
1010import { NATIVE } from '../src/js/wrapper' ;
@@ -67,14 +67,20 @@ jest.mock(
6767 { virtual : true }
6868) ;
6969
70- const DEFAULT_OPTIONS : ReactNativeOptions = {
70+ const DEFAULT_OPTIONS : ReactNativeClientOptions = {
7171 enableNative : true ,
7272 enableNativeCrashHandling : true ,
7373 enableNativeNagger : true ,
7474 autoInitializeNativeSdk : true ,
7575 enableAutoPerformanceTracking : true ,
7676 enableOutOfMemoryTracking : true ,
77- patchGlobalPromise : true
77+ patchGlobalPromise : true ,
78+ integrations : [ ] ,
79+ transport : ( ) => ( {
80+ send : jest . fn ( ) ,
81+ flush : jest . fn ( ) ,
82+ } ) ,
83+ stackParser : jest . fn ( ) . mockReturnValue ( [ ] ) ,
7884} ;
7985
8086afterEach ( ( ) => {
@@ -89,7 +95,7 @@ describe('Tests ReactNativeClient', () => {
8995 ...DEFAULT_OPTIONS ,
9096 dsn : EXAMPLE_DSN ,
9197 transport : ( ) => new NativeTransport ( )
92- } as ReactNativeClientOptions ) ;
98+ } ) ;
9399
94100 await expect ( client . eventFromMessage ( 'test' ) ) . resolves . toBeDefined ( ) ;
95101 // @ts -ignore: Is Mocked
@@ -103,7 +109,7 @@ describe('Tests ReactNativeClient', () => {
103109 ...DEFAULT_OPTIONS ,
104110 dsn : 'not a dsn' ,
105111 transport : ( ) => new NativeTransport ( )
106- } as ReactNativeClientOptions ) ;
112+ } ) ;
107113 } catch ( e : any ) {
108114 expect ( e . message ) . toBe ( 'Invalid Sentry Dsn: not a dsn' ) ;
109115 }
@@ -115,7 +121,7 @@ describe('Tests ReactNativeClient', () => {
115121 ...DEFAULT_OPTIONS ,
116122 dsn : undefined ,
117123 transport : ( ) => new NativeTransport ( )
118- } as ReactNativeClientOptions ) ;
124+ } ) ;
119125
120126 return expect ( backend . eventFromMessage ( 'test' ) ) . resolves . toBeDefined ( ) ;
121127 } ) . not . toThrow ( ) ;
@@ -132,7 +138,7 @@ describe('Tests ReactNativeClient', () => {
132138 ...DEFAULT_OPTIONS ,
133139 dsn : EXAMPLE_DSN ,
134140 transport : myCustomTransportFn
135- } as ReactNativeClientOptions ) ;
141+ } ) ;
136142 // eslint-disable-next-line @typescript-eslint/unbound-method
137143 expect ( client . getTransport ( ) ?. flush ) . toBe ( myFlush ) ;
138144 // eslint-disable-next-line @typescript-eslint/unbound-method
@@ -142,7 +148,7 @@ describe('Tests ReactNativeClient', () => {
142148
143149 describe ( 'onReady' , ( ) => {
144150 test ( 'calls onReady callback with true if Native SDK is initialized' , ( done ) => {
145- new ReactNativeClient ( {
151+ new ReactNativeClient ( mockedOptions ( {
146152 dsn : EXAMPLE_DSN ,
147153 enableNative : true ,
148154 onReady : ( { didCallNativeInit } ) => {
@@ -151,11 +157,11 @@ describe('Tests ReactNativeClient', () => {
151157 done ( ) ;
152158 } ,
153159 transport : ( ) => new NativeTransport ( )
154- } as ReactNativeOptions as ReactNativeClientOptions ) ;
160+ } ) ) ;
155161 } ) ;
156162
157163 test ( 'calls onReady callback with false if Native SDK was not initialized' , ( done ) => {
158- new ReactNativeClient ( {
164+ new ReactNativeClient ( mockedOptions ( {
159165 dsn : EXAMPLE_DSN ,
160166 enableNative : false ,
161167 onReady : ( { didCallNativeInit } ) => {
@@ -164,7 +170,7 @@ describe('Tests ReactNativeClient', () => {
164170 done ( ) ;
165171 } ,
166172 transport : ( ) => new NativeTransport ( )
167- } as ReactNativeOptions as ReactNativeClientOptions ) ;
173+ } ) ) ;
168174 } ) ;
169175
170176 test ( 'calls onReady callback with false if Native SDK failed to initialize' , ( done ) => {
@@ -174,7 +180,7 @@ describe('Tests ReactNativeClient', () => {
174180 throw new Error ( ) ;
175181 } ) ;
176182
177- new ReactNativeClient ( {
183+ new ReactNativeClient ( mockedOptions ( {
178184 dsn : EXAMPLE_DSN ,
179185 enableNative : true ,
180186 onReady : ( { didCallNativeInit } ) => {
@@ -183,7 +189,7 @@ describe('Tests ReactNativeClient', () => {
183189 done ( ) ;
184190 } ,
185191 transport : ( ) => new NativeTransport ( )
186- } as ReactNativeOptions as ReactNativeClientOptions ) ;
192+ } ) ) ;
187193 } ) ;
188194 } ) ;
189195
@@ -196,7 +202,7 @@ describe('Tests ReactNativeClient', () => {
196202 enableNative : true ,
197203 transport : ( ) => new NativeTransport ( )
198204
199- } as ReactNativeClientOptions ) ;
205+ } ) ;
200206 client . nativeCrash ( ) ;
201207
202208 expect ( RN . NativeModules . RNSentry . crash ) . toBeCalled ( ) ;
@@ -213,7 +219,7 @@ describe('Tests ReactNativeClient', () => {
213219 send : mockTransportSend ,
214220 flush : jest . fn ( ) ,
215221 } ) ,
216- } as ReactNativeClientOptions ) ;
222+ } ) ;
217223
218224 client . captureUserFeedback ( {
219225 comments : 'Test Comments' ,
@@ -281,7 +287,7 @@ describe('Tests ReactNativeClient', () => {
281287 send : mockTransportSend ,
282288 flush : jest . fn ( ) ,
283289 } ) ,
284- } as ReactNativeClientOptions ) ;
290+ } ) ;
285291 } ) ;
286292
287293 afterEach ( ( ) => {
@@ -325,7 +331,7 @@ describe('Tests ReactNativeClient', () => {
325331 send : mockedSend ,
326332 flush : jest . fn ( ) . mockResolvedValue ( true ) ,
327333 } ) ;
328- const client = new ReactNativeClient ( < ReactNativeClientOptions > {
334+ const client = new ReactNativeClient ( {
329335 ...DEFAULT_OPTIONS ,
330336 dsn : EXAMPLE_DSN ,
331337 transport : mockedTransport ,
@@ -351,7 +357,7 @@ describe('Tests ReactNativeClient', () => {
351357 send : mockedSend ,
352358 flush : jest . fn ( ) . mockResolvedValue ( true ) ,
353359 } ) ;
354- const client = new ReactNativeClient ( < ReactNativeClientOptions > {
360+ const client = new ReactNativeClient ( {
355361 ...DEFAULT_OPTIONS ,
356362 dsn : EXAMPLE_DSN ,
357363 transport : mockedTransport ,
@@ -386,7 +392,7 @@ describe('Tests ReactNativeClient', () => {
386392 flush : jest . fn ( ) ,
387393 } ) ,
388394 sendClientReports : false ,
389- } as ReactNativeClientOptions ) ;
395+ } ) ;
390396
391397 mockDroppedEvent ( client ) ;
392398
@@ -405,7 +411,7 @@ describe('Tests ReactNativeClient', () => {
405411 flush : jest . fn ( ) ,
406412 } ) ,
407413 sendClientReports : true ,
408- } as ReactNativeClientOptions ) ;
414+ } ) ;
409415
410416 mockDroppedEvent ( client ) ;
411417
@@ -439,7 +445,7 @@ describe('Tests ReactNativeClient', () => {
439445 flush : jest . fn ( ) ,
440446 } ) ,
441447 sendClientReports : true ,
442- } as ReactNativeClientOptions ) ;
448+ } ) ;
443449
444450 client . captureMessage ( 'message_test_value' ) ;
445451
@@ -457,7 +463,7 @@ describe('Tests ReactNativeClient', () => {
457463 flush : jest . fn ( ) ,
458464 } ) ,
459465 sendClientReports : true ,
460- } as ReactNativeClientOptions ) ;
466+ } ) ;
461467
462468 mockDroppedEvent ( client ) ;
463469
@@ -478,7 +484,7 @@ describe('Tests ReactNativeClient', () => {
478484 flush : jest . fn ( ) ,
479485 } ) ,
480486 sendClientReports : true ,
481- } as ReactNativeClientOptions ) ;
487+ } ) ;
482488
483489 mockDroppedEvent ( client ) ;
484490 client . captureMessage ( 'message_test_value_1' ) ;
@@ -519,3 +525,15 @@ describe('Tests ReactNativeClient', () => {
519525 }
520526 } ) ;
521527} ) ;
528+
529+ function mockedOptions ( options : Partial < ReactNativeClientOptions > ) : ReactNativeClientOptions {
530+ return {
531+ integrations : [ ] ,
532+ stackParser : jest . fn ( ) . mockReturnValue ( [ ] ) ,
533+ transport : ( ) => ( {
534+ send : jest . fn ( ) ,
535+ flush : jest . fn ( ) ,
536+ } ) ,
537+ ...options ,
538+ } ;
539+ }
0 commit comments