File tree Expand file tree Collapse file tree 3 files changed +4
-25
lines changed Expand file tree Collapse file tree 3 files changed +4
-25
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,7 @@ export const App: React.FC = () => {
35
35
} , [ ] ) ;
36
36
37
37
useEffect ( ( ) => {
38
- const unregisterListener = Instabug . setNavigationListener ( navigationRef ) ;
39
-
40
- return unregisterListener ;
38
+ Instabug . setNavigationListener ( navigationRef ) ;
41
39
} , [ navigationRef ] ) ;
42
40
43
41
return (
Original file line number Diff line number Diff line change @@ -544,7 +544,7 @@ export const onStateChange = (state?: NavigationStateV5) => {
544
544
export const setNavigationListener = (
545
545
navigationRef : NavigationContainerRefWithCurrent < ReactNavigation . RootParamList > ,
546
546
) => {
547
- return navigationRef . addListener ( 'state' , ( ) => {
547
+ navigationRef . addListener ( 'state' , ( ) => {
548
548
onStateChange ( navigationRef . getRootState ( ) ) ;
549
549
} ) ;
550
550
} ;
Original file line number Diff line number Diff line change @@ -238,39 +238,20 @@ describe('Instabug Module', () => {
238
238
} ) ;
239
239
240
240
it ( 'setNavigationListener should call the onStateChange on a screen change' , async ( ) => {
241
- const mockedState = { routes : [ { name : 'ScreenName' } ] , index : 0 } ;
242
-
243
241
const mockNavigationContainerRef = {
244
242
current : null ,
245
243
navigate : jest . fn ( ) ,
246
244
reset : jest . fn ( ) ,
247
245
goBack : jest . fn ( ) ,
248
246
dispatch : jest . fn ( ) ,
249
- getRootState : ( ) => mockedState ,
247
+ getRootState : jest . fn ( ) ,
250
248
canGoBack : jest . fn ( ) ,
251
-
252
- addListener : jest . fn ( ( event , callback ) => {
253
- expect ( event ) . toBe ( 'state' ) ;
254
- callback ( mockedState ) ;
255
- return jest . fn ( ) ;
256
- } ) ,
249
+ addListener : jest . fn ( ) ,
257
250
removeListener : jest . fn ( ) ,
258
251
} as unknown as NavigationContainerRefWithCurrent < ReactNavigation . RootParamList > ;
259
252
260
- const onStateChangeMock = jest . fn ( ) ;
261
-
262
- jest . spyOn ( Instabug , 'onStateChange' ) . mockImplementation ( onStateChangeMock ) ;
263
-
264
253
Instabug . setNavigationListener ( mockNavigationContainerRef ) ;
265
-
266
254
expect ( mockNavigationContainerRef . addListener ) . toBeCalledTimes ( 1 ) ;
267
- expect ( mockNavigationContainerRef . addListener ) . toHaveBeenCalledWith (
268
- 'state' ,
269
- expect . any ( Function ) ,
270
- ) ;
271
-
272
- expect ( onStateChangeMock ) . toBeCalledTimes ( 1 ) ;
273
- expect ( onStateChangeMock ) . toHaveBeenCalledWith ( mockNavigationContainerRef . getRootState ( ) ) ;
274
255
} ) ;
275
256
276
257
it ( 'should call the native method init' , ( ) => {
You can’t perform that action at this time.
0 commit comments