1
1
/* tslint:disable:jsx-wrap-multiline */
2
- import { ICoreReportingAPI } from '@stoplight/reporter ' ;
2
+ import * as Sentry from '@sentry/react ' ;
3
3
import { mount } from 'enzyme' ;
4
4
import * as React from 'react' ;
5
5
@@ -20,23 +20,12 @@ describe('ErrorBoundary component', () => {
20
20
return < span > { String ( value ) } </ span > ;
21
21
} ;
22
22
23
- let reporter : ICoreReportingAPI ;
24
-
25
- beforeEach ( ( ) => {
26
- reporter = {
27
- ...console ,
28
- error : jest . fn ( ) ,
29
- } ;
30
- } ) ;
31
-
32
23
describe ( 'when exception is not thrown' , ( ) => {
33
24
it ( 'renders children' , ( ) => {
34
25
const wrapper = mount (
35
- < ErrorBoundaryProvider reporter = { reporter } >
36
- < ErrorBoundary >
37
- < TestComponent value = "test" />
38
- </ ErrorBoundary >
39
- </ ErrorBoundaryProvider > ,
26
+ < ErrorBoundary >
27
+ < TestComponent value = "test" />
28
+ </ ErrorBoundary > ,
40
29
) ;
41
30
42
31
expect ( wrapper . find ( TestComponent ) ) . toHaveHTML ( '<span>test</span>' ) ;
@@ -48,70 +37,32 @@ describe('ErrorBoundary component', () => {
48
37
describe ( 'when exception is thrown' , ( ) => {
49
38
it ( 'renders fallback component and passes error-related props' , ( ) => {
50
39
const wrapper = mount (
51
- < ErrorBoundaryProvider reporter = { reporter } >
52
- < ErrorBoundary >
53
- < TestComponent value = { 0 } />
54
- </ ErrorBoundary >
55
- </ ErrorBoundaryProvider > ,
40
+ < ErrorBoundary >
41
+ < TestComponent value = { 0 } />
42
+ </ ErrorBoundary > ,
56
43
) ;
57
44
58
45
expect ( wrapper . find ( FallbackComponent ) ) . toExist ( ) ;
59
46
expect ( wrapper . find ( FallbackComponent ) ) . toHaveProp ( {
60
47
error : ex ,
61
48
componentStack : expect . stringContaining ( 'in TestComponent' ) ,
62
- tryRecovering : ( wrapper . find ( ErrorBoundary ) . instance ( ) as any ) . recover ,
49
+ tryRecovering : ( wrapper . find ( Sentry . ErrorBoundary ) . instance ( ) as any ) . resetErrorBoundary ,
63
50
} ) ;
64
51
65
52
wrapper . unmount ( ) ;
66
53
} ) ;
67
54
68
- describe ( 'error reporting' , ( ) => {
69
- it ( 'calls onError prop' , ( ) => {
70
- const onError = jest . fn ( ) ;
71
- const wrapper = mount (
72
- < ErrorBoundaryProvider reporter = { reporter } >
73
- < ErrorBoundary onError = { onError } >
74
- < TestComponent value = { 0 } />
75
- </ ErrorBoundary >
76
- </ ErrorBoundaryProvider > ,
77
- ) ;
78
-
79
- expect ( onError ) . toBeCalledWith ( ex , expect . stringContaining ( 'in TestComponent' ) ) ;
80
-
81
- wrapper . unmount ( ) ;
82
- } ) ;
83
-
84
- it ( 'reports errors by default' , ( ) => {
85
- const wrapper = mount (
86
- < ErrorBoundaryProvider reporter = { reporter } >
87
- < ErrorBoundary >
88
- < TestComponent value = { 0 } />
89
- </ ErrorBoundary >
90
- </ ErrorBoundaryProvider > ,
91
- ) ;
92
-
93
- expect ( reporter . error ) . toBeCalledWith ( ex . message , {
94
- errorInfo : {
95
- componentStack : expect . any ( String ) ,
96
- } ,
97
- } ) ;
98
-
99
- wrapper . unmount ( ) ;
100
- } ) ;
101
-
102
- it ( 'does reports error if reporting is disabled' , ( ) => {
103
- const wrapper = mount (
104
- < ErrorBoundaryProvider reporter = { reporter } >
105
- < ErrorBoundary reportErrors = { false } >
106
- < TestComponent value = { 0 } />
107
- </ ErrorBoundary >
108
- </ ErrorBoundaryProvider > ,
109
- ) ;
55
+ it ( 'calls onError prop' , ( ) => {
56
+ const onError = jest . fn ( ) ;
57
+ const wrapper = mount (
58
+ < ErrorBoundary onError = { onError } >
59
+ < TestComponent value = { 0 } />
60
+ </ ErrorBoundary > ,
61
+ ) ;
110
62
111
- expect ( reporter . error ) . not . toBeCalled ( ) ;
63
+ expect ( onError ) . toBeCalledWith ( ex , expect . stringContaining ( 'in TestComponent' ) , expect . any ( String ) ) ;
112
64
113
- wrapper . unmount ( ) ;
114
- } ) ;
65
+ wrapper . unmount ( ) ;
115
66
} ) ;
116
67
117
68
describe ( 'and a custom fallback component is provided' , ( ) => {
@@ -120,19 +71,17 @@ describe('ErrorBoundary component', () => {
120
71
const CustomFallbackComponent = ( ) => < div > foo</ div > ;
121
72
122
73
const wrapper = mount (
123
- < ErrorBoundaryProvider reporter = { reporter } >
124
- < ErrorBoundary FallbackComponent = { CustomFallbackComponent } >
125
- < TestComponent value = { 0 } />
126
- </ ErrorBoundary >
127
- </ ErrorBoundaryProvider > ,
74
+ < ErrorBoundary FallbackComponent = { CustomFallbackComponent } >
75
+ < TestComponent value = { 0 } />
76
+ </ ErrorBoundary > ,
128
77
) ;
129
78
130
79
expect ( wrapper . find ( FallbackComponent ) ) . not . toExist ( ) ; // makes sure we don't render the original one
131
80
expect ( wrapper . find ( CustomFallbackComponent ) ) . toExist ( ) ;
132
81
expect ( wrapper . find ( CustomFallbackComponent ) ) . toHaveProp ( {
133
82
error : ex ,
134
83
componentStack : expect . stringContaining ( 'in TestComponent' ) ,
135
- tryRecovering : ( wrapper . find ( ErrorBoundary ) . instance ( ) as any ) . recover ,
84
+ tryRecovering : ( wrapper . find ( Sentry . ErrorBoundary ) . instance ( ) as any ) . resetErrorBoundary ,
136
85
} ) ;
137
86
138
87
wrapper . unmount ( ) ;
@@ -144,7 +93,7 @@ describe('ErrorBoundary component', () => {
144
93
const CustomFallbackComponent = ( ) => < div > foo</ div > ;
145
94
146
95
const wrapper = mount (
147
- < ErrorBoundaryProvider reporter = { reporter } FallbackComponent = { CustomFallbackComponent } >
96
+ < ErrorBoundaryProvider FallbackComponent = { CustomFallbackComponent } >
148
97
>
149
98
< ErrorBoundary >
150
99
< TestComponent value = { 0 } />
@@ -157,7 +106,7 @@ describe('ErrorBoundary component', () => {
157
106
expect ( wrapper . find ( CustomFallbackComponent ) ) . toHaveProp ( {
158
107
error : ex ,
159
108
componentStack : expect . stringContaining ( 'in TestComponent' ) ,
160
- tryRecovering : ( wrapper . find ( ErrorBoundary ) . instance ( ) as any ) . recover ,
109
+ tryRecovering : ( wrapper . find ( Sentry . ErrorBoundary ) . instance ( ) as any ) . resetErrorBoundary ,
161
110
} ) ;
162
111
163
112
wrapper . unmount ( ) ;
@@ -170,7 +119,7 @@ describe('ErrorBoundary component', () => {
170
119
const CustomFallbackPropsComponent = ( ) => < div > level!</ div > ;
171
120
172
121
const wrapper = mount (
173
- < ErrorBoundaryProvider reporter = { reporter } FallbackComponent = { CustomFallbackContextComponent } >
122
+ < ErrorBoundaryProvider FallbackComponent = { CustomFallbackContextComponent } >
174
123
< ErrorBoundary FallbackComponent = { CustomFallbackPropsComponent } >
175
124
< TestComponent value = { 0 } />
176
125
</ ErrorBoundary >
@@ -190,11 +139,9 @@ describe('ErrorBoundary component', () => {
190
139
const getValue = jest . fn ( ) . mockReturnValue ( 0 ) ;
191
140
192
141
const wrapper = mount (
193
- < ErrorBoundaryProvider reporter = { reporter } >
194
- < ErrorBoundary FallbackComponent = { CustomFallbackComponent } >
195
- < TestComponent getValue = { getValue } />
196
- </ ErrorBoundary >
197
- </ ErrorBoundaryProvider > ,
142
+ < ErrorBoundary FallbackComponent = { CustomFallbackComponent } >
143
+ < TestComponent getValue = { getValue } />
144
+ </ ErrorBoundary > ,
198
145
) ;
199
146
200
147
expect ( wrapper . find ( CustomFallbackComponent ) ) . toExist ( ) ;
0 commit comments