File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
test/unit/features/global-api Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,24 @@ export default class Watcher {
188
188
// set new value
189
189
const oldValue = this . value
190
190
this . value = value
191
- this . cb . call ( this . vm , value , oldValue )
191
+ if ( this . user ) {
192
+ try {
193
+ this . cb . call ( this . vm , value , oldValue )
194
+ } catch ( e ) {
195
+ process . env . NODE_ENV !== 'production' && warn (
196
+ `Error in watcher "${ this . expression } "` ,
197
+ this . vm
198
+ )
199
+ /* istanbul ignore else */
200
+ if ( config . errorHandler ) {
201
+ config . errorHandler . call ( null , e , this . vm )
202
+ } else {
203
+ throw e
204
+ }
205
+ }
206
+ } else {
207
+ this . cb . call ( this . vm , value , oldValue )
208
+ }
192
209
}
193
210
}
194
211
}
Original file line number Diff line number Diff line change @@ -33,6 +33,25 @@ describe('Global config', () => {
33
33
expect ( spy ) . toHaveBeenCalledWith ( err , vm )
34
34
Vue . config . errorHandler = null
35
35
} )
36
+
37
+ it ( 'should capture user watcher callback errors' , done => {
38
+ const spy = jasmine . createSpy ( 'errorHandler' )
39
+ Vue . config . errorHandler = spy
40
+ const err = new Error ( )
41
+ const vm = new Vue ( {
42
+ data : { a : 1 } ,
43
+ watch : {
44
+ a : ( ) => {
45
+ throw err
46
+ }
47
+ }
48
+ } ) . $mount ( )
49
+ vm . a = 2
50
+ waitForUpdate ( ( ) => {
51
+ expect ( spy ) . toHaveBeenCalledWith ( err , vm )
52
+ Vue . config . errorHandler = null
53
+ } ) . then ( done )
54
+ } )
36
55
} )
37
56
38
57
describe ( 'optionMergeStrategies' , ( ) => {
You can’t perform that action at this time.
0 commit comments