@@ -31,8 +31,8 @@ describe('Options errorCaptured', () => {
31
31
} ) . $mount ( )
32
32
33
33
expect ( spy ) . toHaveBeenCalledWith ( err , child , 'created hook' )
34
- // should not propagate by default
35
- expect ( globalSpy ) . not . toHaveBeenCalled ( )
34
+ // should propagate by default
35
+ expect ( globalSpy ) . toHaveBeenCalledWith ( err , child , 'created hook' )
36
36
} )
37
37
38
38
it ( 'should be able to render the error in itself' , done => {
@@ -67,7 +67,7 @@ describe('Options errorCaptured', () => {
67
67
} ) . then ( done )
68
68
} )
69
69
70
- it ( 'should propagate to global handler when returning true' , ( ) => {
70
+ it ( 'should not propagate to global handler when returning true' , ( ) => {
71
71
const spy = jasmine . createSpy ( )
72
72
73
73
let child
@@ -84,14 +84,14 @@ describe('Options errorCaptured', () => {
84
84
new Vue ( {
85
85
errorCaptured ( err , vm , info ) {
86
86
spy ( err , vm , info )
87
- return true
87
+ return false
88
88
} ,
89
89
render : h => h ( Child , { } )
90
90
} ) . $mount ( )
91
91
92
92
expect ( spy ) . toHaveBeenCalledWith ( err , child , 'created hook' )
93
- // should propagate
94
- expect ( globalSpy ) . toHaveBeenCalledWith ( err , child , 'created hook' )
93
+ // should not propagate
94
+ expect ( globalSpy ) . not . toHaveBeenCalled ( )
95
95
} )
96
96
97
97
it ( 'should propagate to global handler if itself throws error' , ( ) => {
@@ -118,4 +118,95 @@ describe('Options errorCaptured', () => {
118
118
expect ( globalSpy ) . toHaveBeenCalledWith ( err , child , 'created hook' )
119
119
expect ( globalSpy ) . toHaveBeenCalledWith ( err2 , vm , 'errorCaptured hook' )
120
120
} )
121
+
122
+ it ( 'should work across multiple parents, mixins and extends' , ( ) => {
123
+ const calls = [ ]
124
+
125
+ const Child = {
126
+ created ( ) {
127
+ throw new Error ( 'child' )
128
+ } ,
129
+ render ( ) { }
130
+ }
131
+
132
+ const ErrorBoundaryBase = {
133
+ errorCaptured ( ) {
134
+ calls . push ( 1 )
135
+ }
136
+ }
137
+
138
+ const mixin = {
139
+ errorCaptured ( ) {
140
+ calls . push ( 2 )
141
+ }
142
+ }
143
+
144
+ const ErrorBoundaryExtended = {
145
+ extends : ErrorBoundaryBase ,
146
+ mixins : [ mixin ] ,
147
+ errorCaptured ( ) {
148
+ calls . push ( 3 )
149
+ } ,
150
+ render : h => h ( Child )
151
+ }
152
+
153
+ Vue . config . errorHandler = ( ) => {
154
+ calls . push ( 5 )
155
+ }
156
+
157
+ new Vue ( {
158
+ errorCaptured ( ) {
159
+ calls . push ( 4 )
160
+ } ,
161
+ render : h => h ( ErrorBoundaryExtended )
162
+ } ) . $mount ( )
163
+
164
+ expect ( calls ) . toEqual ( [ 1 , 2 , 3 , 4 , 5 ] )
165
+ } )
166
+
167
+ it ( 'should work across multiple parents, mixins and extends with return false' , ( ) => {
168
+ const calls = [ ]
169
+
170
+ const Child = {
171
+ created ( ) {
172
+ throw new Error ( 'child' )
173
+ } ,
174
+ render ( ) { }
175
+ }
176
+
177
+ const ErrorBoundaryBase = {
178
+ errorCaptured ( ) {
179
+ calls . push ( 1 )
180
+ }
181
+ }
182
+
183
+ const mixin = {
184
+ errorCaptured ( ) {
185
+ calls . push ( 2 )
186
+ }
187
+ }
188
+
189
+ const ErrorBoundaryExtended = {
190
+ extends : ErrorBoundaryBase ,
191
+ mixins : [ mixin ] ,
192
+ errorCaptured ( ) {
193
+ calls . push ( 3 )
194
+ return false
195
+ } ,
196
+ render : h => h ( Child )
197
+ }
198
+
199
+ Vue . config . errorHandler = ( ) => {
200
+ calls . push ( 5 )
201
+ }
202
+
203
+ new Vue ( {
204
+ errorCaptured ( ) {
205
+ calls . push ( 4 )
206
+ } ,
207
+ render : h => h ( ErrorBoundaryExtended )
208
+ } ) . $mount ( )
209
+
210
+ expect ( calls ) . toEqual ( [ 1 , 2 , 3 ] )
211
+ } )
121
212
} )
0 commit comments