@@ -3,7 +3,7 @@ import { rejectedSyncPromise, SentryError } from '@sentry/utils';
33import * as RN from 'react-native' ;
44
55import { ReactNativeClient } from '../src/js/client' ;
6- import { ReactNativeClientOptions , ReactNativeOptions } from '../src/js/options' ;
6+ import { ReactNativeClientOptions } from '../src/js/options' ;
77import { NativeTransport } from '../src/js/transports/native' ;
88import { SDK_NAME , SDK_PACKAGE_NAME , SDK_VERSION } from '../src/js/version' ;
99import { NATIVE } from '../src/js/wrapper' ;
@@ -66,14 +66,20 @@ jest.mock(
6666 { virtual : true }
6767) ;
6868
69- const DEFAULT_OPTIONS : ReactNativeOptions = {
69+ const DEFAULT_OPTIONS : ReactNativeClientOptions = {
7070 enableNative : true ,
7171 enableNativeCrashHandling : true ,
7272 enableNativeNagger : true ,
7373 autoInitializeNativeSdk : true ,
7474 enableAutoPerformanceTracking : true ,
7575 enableOutOfMemoryTracking : true ,
76- patchGlobalPromise : true
76+ patchGlobalPromise : true ,
77+ integrations : [ ] ,
78+ transport : ( ) => ( {
79+ send : jest . fn ( ) ,
80+ flush : jest . fn ( ) ,
81+ } ) ,
82+ stackParser : jest . fn ( ) . mockReturnValue ( [ ] ) ,
7783} ;
7884
7985afterEach ( ( ) => {
@@ -88,7 +94,7 @@ describe('Tests ReactNativeClient', () => {
8894 ...DEFAULT_OPTIONS ,
8995 dsn : EXAMPLE_DSN ,
9096 transport : ( ) => new NativeTransport ( )
91- } as ReactNativeClientOptions ) ;
97+ } ) ;
9298
9399 await expect ( client . eventFromMessage ( 'test' ) ) . resolves . toBeDefined ( ) ;
94100 // @ts -ignore: Is Mocked
@@ -102,7 +108,7 @@ describe('Tests ReactNativeClient', () => {
102108 ...DEFAULT_OPTIONS ,
103109 dsn : 'not a dsn' ,
104110 transport : ( ) => new NativeTransport ( )
105- } as ReactNativeClientOptions ) ;
111+ } ) ;
106112 } catch ( e : any ) {
107113 expect ( e . message ) . toBe ( 'Invalid Sentry Dsn: not a dsn' ) ;
108114 }
@@ -114,7 +120,7 @@ describe('Tests ReactNativeClient', () => {
114120 ...DEFAULT_OPTIONS ,
115121 dsn : undefined ,
116122 transport : ( ) => new NativeTransport ( )
117- } as ReactNativeClientOptions ) ;
123+ } ) ;
118124
119125 return expect ( backend . eventFromMessage ( 'test' ) ) . resolves . toBeDefined ( ) ;
120126 } ) . not . toThrow ( ) ;
@@ -131,7 +137,7 @@ describe('Tests ReactNativeClient', () => {
131137 ...DEFAULT_OPTIONS ,
132138 dsn : EXAMPLE_DSN ,
133139 transport : myCustomTransportFn
134- } as ReactNativeClientOptions ) ;
140+ } ) ;
135141 // eslint-disable-next-line @typescript-eslint/unbound-method
136142 expect ( client . getTransport ( ) ?. flush ) . toBe ( myFlush ) ;
137143 // eslint-disable-next-line @typescript-eslint/unbound-method
@@ -141,7 +147,7 @@ describe('Tests ReactNativeClient', () => {
141147
142148 describe ( 'onReady' , ( ) => {
143149 test ( 'calls onReady callback with true if Native SDK is initialized' , ( done ) => {
144- new ReactNativeClient ( {
150+ new ReactNativeClient ( mockedOptions ( {
145151 dsn : EXAMPLE_DSN ,
146152 enableNative : true ,
147153 onReady : ( { didCallNativeInit } ) => {
@@ -150,11 +156,11 @@ describe('Tests ReactNativeClient', () => {
150156 done ( ) ;
151157 } ,
152158 transport : ( ) => new NativeTransport ( )
153- } as ReactNativeOptions as ReactNativeClientOptions ) ;
159+ } ) ) ;
154160 } ) ;
155161
156162 test ( 'calls onReady callback with false if Native SDK was not initialized' , ( done ) => {
157- new ReactNativeClient ( {
163+ new ReactNativeClient ( mockedOptions ( {
158164 dsn : EXAMPLE_DSN ,
159165 enableNative : false ,
160166 onReady : ( { didCallNativeInit } ) => {
@@ -163,7 +169,7 @@ describe('Tests ReactNativeClient', () => {
163169 done ( ) ;
164170 } ,
165171 transport : ( ) => new NativeTransport ( )
166- } as ReactNativeOptions as ReactNativeClientOptions ) ;
172+ } ) ) ;
167173 } ) ;
168174
169175 test ( 'calls onReady callback with false if Native SDK failed to initialize' , ( done ) => {
@@ -173,7 +179,7 @@ describe('Tests ReactNativeClient', () => {
173179 throw new Error ( ) ;
174180 } ) ;
175181
176- new ReactNativeClient ( {
182+ new ReactNativeClient ( mockedOptions ( {
177183 dsn : EXAMPLE_DSN ,
178184 enableNative : true ,
179185 onReady : ( { didCallNativeInit } ) => {
@@ -182,7 +188,7 @@ describe('Tests ReactNativeClient', () => {
182188 done ( ) ;
183189 } ,
184190 transport : ( ) => new NativeTransport ( )
185- } as ReactNativeOptions as ReactNativeClientOptions ) ;
191+ } ) ) ;
186192 } ) ;
187193 } ) ;
188194
@@ -195,7 +201,7 @@ describe('Tests ReactNativeClient', () => {
195201 enableNative : true ,
196202 transport : ( ) => new NativeTransport ( )
197203
198- } as ReactNativeClientOptions ) ;
204+ } ) ;
199205 client . nativeCrash ( ) ;
200206
201207 expect ( RN . NativeModules . RNSentry . crash ) . toBeCalled ( ) ;
@@ -212,7 +218,7 @@ describe('Tests ReactNativeClient', () => {
212218 send : mockTransportSend ,
213219 flush : jest . fn ( ) ,
214220 } ) ,
215- } as ReactNativeClientOptions ) ;
221+ } ) ;
216222
217223 client . captureUserFeedback ( {
218224 comments : 'Test Comments' ,
@@ -247,7 +253,7 @@ describe('Tests ReactNativeClient', () => {
247253 send : mockTransportSend ,
248254 flush : jest . fn ( ) ,
249255 } ) ,
250- } as ReactNativeClientOptions ) ;
256+ } ) ;
251257 } ) ;
252258
253259 afterEach ( ( ) => {
@@ -291,7 +297,7 @@ describe('Tests ReactNativeClient', () => {
291297 send : mockedSend ,
292298 flush : jest . fn ( ) . mockResolvedValue ( true ) ,
293299 } ) ;
294- const client = new ReactNativeClient ( < ReactNativeClientOptions > {
300+ const client = new ReactNativeClient ( {
295301 ...DEFAULT_OPTIONS ,
296302 dsn : EXAMPLE_DSN ,
297303 transport : mockedTransport ,
@@ -317,7 +323,7 @@ describe('Tests ReactNativeClient', () => {
317323 send : mockedSend ,
318324 flush : jest . fn ( ) . mockResolvedValue ( true ) ,
319325 } ) ;
320- const client = new ReactNativeClient ( < ReactNativeClientOptions > {
326+ const client = new ReactNativeClient ( {
321327 ...DEFAULT_OPTIONS ,
322328 dsn : EXAMPLE_DSN ,
323329 transport : mockedTransport ,
@@ -352,7 +358,7 @@ describe('Tests ReactNativeClient', () => {
352358 flush : jest . fn ( ) ,
353359 } ) ,
354360 sendClientReports : false ,
355- } as ReactNativeClientOptions ) ;
361+ } ) ;
356362
357363 mockDroppedEvent ( client ) ;
358364
@@ -371,7 +377,7 @@ describe('Tests ReactNativeClient', () => {
371377 flush : jest . fn ( ) ,
372378 } ) ,
373379 sendClientReports : true ,
374- } as ReactNativeClientOptions ) ;
380+ } ) ;
375381
376382 mockDroppedEvent ( client ) ;
377383
@@ -405,7 +411,7 @@ describe('Tests ReactNativeClient', () => {
405411 flush : jest . fn ( ) ,
406412 } ) ,
407413 sendClientReports : true ,
408- } as ReactNativeClientOptions ) ;
414+ } ) ;
409415
410416 client . captureMessage ( 'message_test_value' ) ;
411417
@@ -423,7 +429,7 @@ describe('Tests ReactNativeClient', () => {
423429 flush : jest . fn ( ) ,
424430 } ) ,
425431 sendClientReports : true ,
426- } as ReactNativeClientOptions ) ;
432+ } ) ;
427433
428434 mockDroppedEvent ( client ) ;
429435
@@ -444,7 +450,7 @@ describe('Tests ReactNativeClient', () => {
444450 flush : jest . fn ( ) ,
445451 } ) ,
446452 sendClientReports : true ,
447- } as ReactNativeClientOptions ) ;
453+ } ) ;
448454
449455 mockDroppedEvent ( client ) ;
450456 client . captureMessage ( 'message_test_value_1' ) ;
@@ -485,3 +491,15 @@ describe('Tests ReactNativeClient', () => {
485491 }
486492 } ) ;
487493} ) ;
494+
495+ function mockedOptions ( options : Partial < ReactNativeClientOptions > ) : ReactNativeClientOptions {
496+ return {
497+ integrations : [ ] ,
498+ stackParser : jest . fn ( ) . mockReturnValue ( [ ] ) ,
499+ transport : ( ) => ( {
500+ send : jest . fn ( ) ,
501+ flush : jest . fn ( ) ,
502+ } ) ,
503+ ...options ,
504+ } ;
505+ }
0 commit comments