1- /* eslint-disable no-console */
1+ import { debug } from '@sentry/core' ;
22import { defaultNativeLogHandler , setupNativeLogListener } from '../src/js/NativeLogListener' ;
33import type { NativeLogEntry } from '../src/js/options' ;
44
@@ -16,6 +16,14 @@ jest.mock('react-native', () => ({
1616 } ,
1717} ) ) ;
1818
19+ jest . mock ( '@sentry/core' , ( ) => ( {
20+ debug : {
21+ log : jest . fn ( ) ,
22+ warn : jest . fn ( ) ,
23+ error : jest . fn ( ) ,
24+ } ,
25+ } ) ) ;
26+
1927describe ( 'NativeLogListener' , ( ) => {
2028 beforeEach ( ( ) => {
2129 jest . clearAllMocks ( ) ;
@@ -53,23 +61,7 @@ describe('NativeLogListener', () => {
5361 } ) ;
5462
5563 describe ( 'defaultNativeLogHandler' , ( ) => {
56- const originalConsole = { ...console } ;
57-
58- beforeEach ( ( ) => {
59- console . log = jest . fn ( ) ;
60- console . info = jest . fn ( ) ;
61- console . warn = jest . fn ( ) ;
62- console . error = jest . fn ( ) ;
63- } ) ;
64-
65- afterEach ( ( ) => {
66- console . log = originalConsole . log ;
67- console . info = originalConsole . info ;
68- console . warn = originalConsole . warn ;
69- console . error = originalConsole . error ;
70- } ) ;
71-
72- it ( 'logs error level to console.error' , ( ) => {
64+ it ( 'logs error level using debug.error' , ( ) => {
7365 const log : NativeLogEntry = {
7466 level : 'error' ,
7567 component : 'TestComponent' ,
@@ -78,10 +70,10 @@ describe('NativeLogListener', () => {
7870
7971 defaultNativeLogHandler ( log ) ;
8072
81- expect ( console . error ) . toHaveBeenCalledWith ( '[Sentry] [ERROR ] [TestComponent] Test error message' ) ;
73+ expect ( debug . error ) . toHaveBeenCalledWith ( '[Native ] [TestComponent] Test error message' ) ;
8274 } ) ;
8375
84- it ( 'logs fatal level to console .error' , ( ) => {
76+ it ( 'logs fatal level using debug .error' , ( ) => {
8577 const log : NativeLogEntry = {
8678 level : 'fatal' ,
8779 component : 'TestComponent' ,
@@ -90,10 +82,10 @@ describe('NativeLogListener', () => {
9082
9183 defaultNativeLogHandler ( log ) ;
9284
93- expect ( console . error ) . toHaveBeenCalledWith ( '[Sentry] [FATAL ] [TestComponent] Test fatal message' ) ;
85+ expect ( debug . error ) . toHaveBeenCalledWith ( '[Native ] [TestComponent] Test fatal message' ) ;
9486 } ) ;
9587
96- it ( 'logs warning level to console .warn' , ( ) => {
88+ it ( 'logs warning level using debug .warn' , ( ) => {
9789 const log : NativeLogEntry = {
9890 level : 'warning' ,
9991 component : 'TestComponent' ,
@@ -102,10 +94,10 @@ describe('NativeLogListener', () => {
10294
10395 defaultNativeLogHandler ( log ) ;
10496
105- expect ( console . warn ) . toHaveBeenCalledWith ( '[Sentry] [WARNING ] [TestComponent] Test warning message' ) ;
97+ expect ( debug . warn ) . toHaveBeenCalledWith ( '[Native ] [TestComponent] Test warning message' ) ;
10698 } ) ;
10799
108- it ( 'logs info level to console.info ' , ( ) => {
100+ it ( 'logs info level using debug.log ' , ( ) => {
109101 const log : NativeLogEntry = {
110102 level : 'info' ,
111103 component : 'TestComponent' ,
@@ -114,10 +106,10 @@ describe('NativeLogListener', () => {
114106
115107 defaultNativeLogHandler ( log ) ;
116108
117- expect ( console . info ) . toHaveBeenCalledWith ( '[Sentry] [INFO ] [TestComponent] Test info message' ) ;
109+ expect ( debug . log ) . toHaveBeenCalledWith ( '[Native ] [TestComponent] Test info message' ) ;
118110 } ) ;
119111
120- it ( 'logs debug level to console .log' , ( ) => {
112+ it ( 'logs debug level using debug .log' , ( ) => {
121113 const log : NativeLogEntry = {
122114 level : 'debug' ,
123115 component : 'TestComponent' ,
@@ -126,10 +118,10 @@ describe('NativeLogListener', () => {
126118
127119 defaultNativeLogHandler ( log ) ;
128120
129- expect ( console . log ) . toHaveBeenCalledWith ( '[Sentry] [DEBUG ] [TestComponent] Test debug message' ) ;
121+ expect ( debug . log ) . toHaveBeenCalledWith ( '[Native ] [TestComponent] Test debug message' ) ;
130122 } ) ;
131123
132- it ( 'logs unknown level to console .log' , ( ) => {
124+ it ( 'logs unknown level using debug .log' , ( ) => {
133125 const log : NativeLogEntry = {
134126 level : 'unknown' ,
135127 component : 'TestComponent' ,
@@ -138,7 +130,7 @@ describe('NativeLogListener', () => {
138130
139131 defaultNativeLogHandler ( log ) ;
140132
141- expect ( console . log ) . toHaveBeenCalledWith ( '[Sentry] [UNKNOWN ] [TestComponent] Test unknown message' ) ;
133+ expect ( debug . log ) . toHaveBeenCalledWith ( '[Native ] [TestComponent] Test unknown message' ) ;
142134 } ) ;
143135 } ) ;
144136} ) ;
0 commit comments