@@ -133,7 +133,7 @@ function runExceptionsManagerTests() {
133
133
) ;
134
134
expect ( exceptionData . isFatal ) . toBe ( false ) ;
135
135
expect ( logToConsoleInReact ) . toBe ( false ) ;
136
- expect ( console . error ) . toBeCalledWith ( formattedMessage ) ;
136
+ expect ( console . error ) . toBeCalledWith ( error ) ;
137
137
} ) ;
138
138
139
139
test ( 'does not pop frames off the stack with framesToPop' , ( ) => {
@@ -163,16 +163,10 @@ function runExceptionsManagerTests() {
163
163
expect ( nativeReportException ) . toBeCalledTimes ( 1 ) ;
164
164
exceptionData = nativeReportException . mock . calls [ 0 ] [ 0 ] ;
165
165
}
166
- const formattedMessage =
167
- 'Error: ' +
168
- error . message +
169
- '\n\n' +
170
- 'This error is located at:' +
171
- capturedErrorDefaults . componentStack ;
172
166
expect ( getLineFromFrame ( exceptionData . stack [ 0 ] ) ) . toBe (
173
167
"const error = new Error('Some error happened');" ,
174
168
) ;
175
- expect ( console . error ) . toBeCalledWith ( formattedMessage ) ;
169
+ expect ( console . error ) . toBeCalledWith ( error ) ;
176
170
} ) ;
177
171
178
172
test ( 'wraps string in an Error and sends to handleException' , ( ) => {
@@ -211,7 +205,13 @@ function runExceptionsManagerTests() {
211
205
) ;
212
206
expect ( exceptionData . isFatal ) . toBe ( false ) ;
213
207
expect ( logToConsoleInReact ) . toBe ( false ) ;
214
- expect ( console . error ) . toBeCalledWith ( formattedMessage ) ;
208
+ expect ( console . error ) . toBeCalledTimes ( 1 ) ;
209
+ // $FlowFixMe[prop-missing]
210
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBeInstanceOf (
211
+ ExceptionsManager . SyntheticError ,
212
+ ) ;
213
+ // $FlowFixMe[prop-missing]
214
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe ( message ) ;
215
215
} ) ;
216
216
217
217
test ( 'reports "Unspecified error" if error is null' , ( ) => {
@@ -249,7 +249,15 @@ function runExceptionsManagerTests() {
249
249
) ;
250
250
expect ( exceptionData . isFatal ) . toBe ( false ) ;
251
251
expect ( logToConsoleInReact ) . toBe ( false ) ;
252
- expect ( console . error ) . toBeCalledWith ( formattedMessage ) ;
252
+ expect ( console . error ) . toBeCalledTimes ( 1 ) ;
253
+ // $FlowFixMe[prop-missing]
254
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBeInstanceOf (
255
+ ExceptionsManager . SyntheticError ,
256
+ ) ;
257
+ // $FlowFixMe[prop-missing]
258
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
259
+ 'Unspecified error' ,
260
+ ) ;
253
261
} ) ;
254
262
255
263
test ( 'works with a frozen error object' , ( ) => {
@@ -280,7 +288,7 @@ function runExceptionsManagerTests() {
280
288
// No component stack.
281
289
const formattedMessage = 'Error: ' + error . message ;
282
290
expect ( exceptionData . message ) . toBe ( formattedMessage ) ;
283
- expect ( console . error ) . toBeCalledWith ( formattedMessage ) ;
291
+ expect ( console . error ) . toBeCalledWith ( error ) ;
284
292
} ) ;
285
293
286
294
test ( 'does not mutate the message' , ( ) => {
@@ -312,7 +320,7 @@ function runExceptionsManagerTests() {
312
320
'This error is located at:' +
313
321
capturedErrorDefaults . componentStack ;
314
322
expect ( exceptionData . message ) . toBe ( formattedMessage ) ;
315
- expect ( console . error ) . toBeCalledWith ( formattedMessage ) ;
323
+ expect ( console . error ) . toBeCalledWith ( error ) ;
316
324
} ) ;
317
325
318
326
test ( 'can safely process the same error multiple times' , ( ) => {
@@ -360,7 +368,7 @@ function runExceptionsManagerTests() {
360
368
) ;
361
369
expect ( exceptionData . isFatal ) . toBe ( false ) ;
362
370
expect ( logToConsoleInReact ) . toBe ( false ) ;
363
- expect ( console . error ) . toBeCalledWith ( formattedMessage ) ;
371
+ expect ( console . error ) . toBeCalledWith ( error ) ;
364
372
}
365
373
} ) ;
366
374
} ) ;
@@ -664,7 +672,7 @@ function runExceptionsManagerTests() {
664
672
// $FlowFixMe[prop-missing]
665
673
expect ( console . error . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
666
674
// $FlowFixMe[prop-missing]
667
- expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBe ( formattedMessage ) ;
675
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
668
676
} ) ;
669
677
670
678
test ( 'handling a non-fatal Error' , ( ) => {
@@ -697,7 +705,7 @@ function runExceptionsManagerTests() {
697
705
// $FlowFixMe[prop-missing]
698
706
expect ( console . error . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
699
707
// $FlowFixMe[prop-missing]
700
- expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBe ( formattedMessage ) ;
708
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
701
709
} ) ;
702
710
703
711
test ( 'handling a thrown string' , ( ) => {
@@ -726,7 +734,11 @@ function runExceptionsManagerTests() {
726
734
// $FlowFixMe[prop-missing]
727
735
expect ( console . error . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
728
736
// $FlowFixMe[prop-missing]
729
- expect ( console . error . mock . calls [ 0 ] ) . toEqual ( [ message ] ) ;
737
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBeInstanceOf (
738
+ ExceptionsManager . SyntheticError ,
739
+ ) ;
740
+ // $FlowFixMe[prop-missing]
741
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe ( message ) ;
730
742
} ) ;
731
743
732
744
test ( 'does not pop frames off the stack with framesToPop' , ( ) => {
@@ -759,9 +771,7 @@ function runExceptionsManagerTests() {
759
771
// $FlowFixMe[prop-missing]
760
772
expect ( console . error . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
761
773
// $FlowFixMe[prop-missing]
762
- expect ( console . error . mock . calls [ 0 ] ) . toEqual ( [
763
- 'Error: ' + error . message ,
764
- ] ) ;
774
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
765
775
} ) ;
766
776
767
777
test ( 'logs fatal "warn"-type errors' , ( ) => {
@@ -783,19 +793,17 @@ function runExceptionsManagerTests() {
783
793
// $FlowFixMe[prop-missing]
784
794
expect ( console . error . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
785
795
// $FlowFixMe[prop-missing]
786
- expect ( console . error . mock . calls [ 0 ] ) . toEqual ( [
787
- 'Error: ' + error . message ,
788
- ] ) ;
796
+ expect ( console . error . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
789
797
} ) ;
790
798
} ) ;
791
799
792
800
describe ( 'unstable_setExceptionDecorator' , ( ) => {
793
- let mockError ;
801
+ let mockConsoleError ;
794
802
beforeEach ( ( ) => {
795
803
// NOTE: We initialise a fresh mock every time using spyOn, above.
796
804
// We can't use `console._errorOriginal` for this, because that's a bound
797
805
// (=wrapped) version of the mock and Jest does not approve.
798
- mockError = console . error ;
806
+ mockConsoleError = console . error ;
799
807
ExceptionsManager . installConsoleErrorReporter ( ) ;
800
808
} ) ;
801
809
@@ -861,15 +869,11 @@ function runExceptionsManagerTests() {
861
869
...beforeDecorator ,
862
870
message : 'decorated: ' + beforeDecorator . message ,
863
871
} ) ;
864
- expect ( mockError ) . toBeCalledTimes ( 2 ) ;
872
+ expect ( mockConsoleError ) . toBeCalledTimes ( 2 ) ;
865
873
// $FlowFixMe[prop-missing]
866
- expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toEqual (
867
- 'Error: Some error happened' ,
868
- ) ;
874
+ expect ( mockConsoleError . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
869
875
// $FlowFixMe[prop-missing]
870
- expect ( mockError . mock . calls [ 1 ] [ 0 ] ) . toMatch (
871
- 'decorated: Error: Some error happened' ,
872
- ) ;
876
+ expect ( mockConsoleError . mock . calls [ 1 ] [ 0 ] ) . toBe ( error ) ;
873
877
} ) ;
874
878
875
879
test ( 'clearing a decorator' , ( ) => {
@@ -893,11 +897,9 @@ function runExceptionsManagerTests() {
893
897
expect ( logBoxAddException ) . not . toBeCalled ( ) ;
894
898
expect ( nativeReportException ) . toBeCalledTimes ( 1 ) ;
895
899
}
896
- expect ( mockError ) . toBeCalledTimes ( 1 ) ;
900
+ expect ( mockConsoleError ) . toBeCalledTimes ( 1 ) ;
897
901
// $FlowFixMe[prop-missing]
898
- expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toEqual (
899
- 'Error: Some error happened' ,
900
- ) ;
902
+ expect ( mockConsoleError . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
901
903
} ) ;
902
904
903
905
test ( 'prevents decorator recursion from error handler' , ( ) => {
@@ -928,15 +930,13 @@ function runExceptionsManagerTests() {
928
930
/ d e c o r a t e d : .* S o m e e r r o r h a p p e n e d / ,
929
931
) ;
930
932
}
931
- expect ( mockError ) . toBeCalledTimes ( 2 ) ;
933
+ expect ( mockConsoleError ) . toBeCalledTimes ( 2 ) ;
932
934
// $FlowFixMe[prop-missing]
933
- expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toMatch (
935
+ expect ( mockConsoleError . mock . calls [ 0 ] [ 0 ] ) . toMatch (
934
936
/ L o g g i n g a n e r r o r w i t h i n t h e d e c o r a t o r / ,
935
937
) ;
936
938
// $FlowFixMe[prop-missing]
937
- expect ( mockError . mock . calls [ 1 ] [ 0 ] ) . toMatch (
938
- / d e c o r a t e d : .* S o m e e r r o r h a p p e n e d / ,
939
- ) ;
939
+ expect ( mockConsoleError . mock . calls [ 1 ] [ 0 ] ) . toBe ( error ) ;
940
940
} ) ;
941
941
942
942
test ( 'prevents decorator recursion from console.error' , ( ) => {
@@ -974,14 +974,14 @@ function runExceptionsManagerTests() {
974
974
/ d e c o r a t e d : .* S o m e e r r o r h a p p e n e d / ,
975
975
) ;
976
976
}
977
- expect ( mockError ) . toBeCalledTimes ( 2 ) ;
977
+ expect ( mockConsoleError ) . toBeCalledTimes ( 2 ) ;
978
978
// console.error calls are chained without exception pre-processing, so decorator doesn't apply
979
979
// $FlowFixMe[prop-missing]
980
- expect ( mockError . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toMatch (
980
+ expect ( mockConsoleError . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toMatch (
981
981
/ E r r o r : S o m e e r r o r h a p p e n e d / ,
982
982
) ;
983
983
// $FlowFixMe[prop-missing]
984
- expect ( mockError . mock . calls [ 1 ] [ 0 ] ) . toMatch (
984
+ expect ( mockConsoleError . mock . calls [ 1 ] [ 0 ] ) . toMatch (
985
985
/ L o g g i n g a n e r r o r w i t h i n t h e d e c o r a t o r / ,
986
986
) ;
987
987
} ) ;
@@ -1012,11 +1012,9 @@ function runExceptionsManagerTests() {
1012
1012
/ E r r o r : S o m e e r r o r h a p p e n e d / ,
1013
1013
) ;
1014
1014
}
1015
- expect ( mockError ) . toBeCalledTimes ( 1 ) ;
1015
+ expect ( mockConsoleError ) . toBeCalledTimes ( 1 ) ;
1016
1016
// $FlowFixMe[prop-missing]
1017
- expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toMatch (
1018
- / E r r o r : S o m e e r r o r h a p p e n e d / ,
1019
- ) ;
1017
+ expect ( mockConsoleError . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
1020
1018
} ) ;
1021
1019
1022
1020
test ( 'can handle throwing decorators recursion when exception is logged' , ( ) => {
@@ -1044,9 +1042,9 @@ function runExceptionsManagerTests() {
1044
1042
/ E r r o r : S o m e e r r o r h a p p e n e d / ,
1045
1043
) ;
1046
1044
}
1047
- expect ( mockError ) . toBeCalledTimes ( 1 ) ;
1045
+ expect ( mockConsoleError ) . toBeCalledTimes ( 1 ) ;
1048
1046
// $FlowFixMe[prop-missing]
1049
- expect ( mockError . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toMatch (
1047
+ expect ( mockConsoleError . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toMatch (
1050
1048
/ E r r o r : S o m e e r r o r h a p p e n e d / ,
1051
1049
) ;
1052
1050
} ) ;
0 commit comments