File tree Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## [ Unreleased] ( https://github.com/Instabug/Instabug-React-Native/compare/v13.3.0...dev )
4
4
5
- ### Fixed
5
+ ### Added
6
6
7
- - Fix Omitted non-error objects when logging errors to ensure only error objects are supported. ([ #1279 ] ( https://github.com/Instabug/Instabug-React-Native/pull/1279 ) ).
7
+ - Add support for Expo Router navigation tracking ([ #1270 ] ( https://github.com/Instabug/Instabug-React-Native/pull/1270 ) ).
8
8
9
9
## [ 13.3.0] ( https://github.com/Instabug/Instabug-React-Native/compare/v13.2.0...v13.3.0 ) (August 4, 2024)
10
10
Original file line number Diff line number Diff line change @@ -35,7 +35,9 @@ export const App: React.FC = () => {
35
35
} , [ ] ) ;
36
36
37
37
useEffect ( ( ) => {
38
- Instabug . setNavigationListener ( navigationRef ) ;
38
+ const unregisterListener = Instabug . setNavigationListener ( navigationRef ) ;
39
+
40
+ return unregisterListener ;
39
41
} , [ navigationRef ] ) ;
40
42
41
43
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
- navigationRef . addListener ( 'state' , ( ) => {
547
+ return navigationRef . addListener ( 'state' , ( ) => {
548
548
onStateChange ( navigationRef . getRootState ( ) ) ;
549
549
} ) ;
550
550
} ;
Original file line number Diff line number Diff line change @@ -238,20 +238,39 @@ 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
+
241
243
const mockNavigationContainerRef = {
242
244
current : null ,
243
245
navigate : jest . fn ( ) ,
244
246
reset : jest . fn ( ) ,
245
247
goBack : jest . fn ( ) ,
246
248
dispatch : jest . fn ( ) ,
247
- getRootState : jest . fn ( ) ,
249
+ getRootState : ( ) => mockedState ,
248
250
canGoBack : jest . fn ( ) ,
249
- addListener : jest . fn ( ) ,
251
+
252
+ addListener : jest . fn ( ( event , callback ) => {
253
+ expect ( event ) . toBe ( 'state' ) ;
254
+ callback ( mockedState ) ;
255
+ return jest . fn ( ) ;
256
+ } ) ,
250
257
removeListener : jest . fn ( ) ,
251
258
} as unknown as NavigationContainerRefWithCurrent < ReactNavigation . RootParamList > ;
252
259
260
+ const onStateChangeMock = jest . fn ( ) ;
261
+
262
+ jest . spyOn ( Instabug , 'onStateChange' ) . mockImplementation ( onStateChangeMock ) ;
263
+
253
264
Instabug . setNavigationListener ( mockNavigationContainerRef ) ;
265
+
254
266
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 ( ) ) ;
255
274
} ) ;
256
275
257
276
it ( 'should call the native method init' , ( ) => {
You can’t perform that action at this time.
0 commit comments