File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
packages/core/computedAsync Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,28 @@ describe('computedAsync', () => {
55
55
expectTypeOf ( data2 ) . toEqualTypeOf < ComputedRef < string > > ( )
56
56
} )
57
57
58
+ it ( 'default onError in computedAsync uses globalThis.reportError' , async ( ) => {
59
+ const originalReportError = globalThis . reportError
60
+ const mockReportError = vi . fn ( )
61
+ globalThis . reportError = mockReportError
62
+
63
+ const error = new Error ( 'An Error Message' )
64
+ const func = vi . fn ( async ( ) => {
65
+ throw error
66
+ } )
67
+
68
+ const data = computedAsync ( func , undefined )
69
+
70
+ expect ( func ) . toBeCalledTimes ( 1 )
71
+
72
+ expect ( data . value ) . toBeUndefined ( )
73
+
74
+ await nextTick ( )
75
+ expect ( data . value ) . toBeUndefined ( )
76
+ expect ( mockReportError ) . toHaveBeenCalledWith ( error )
77
+ globalThis . reportError = originalReportError
78
+ } )
79
+
58
80
it ( 'call onError when error is thrown' , async ( ) => {
59
81
const errorMessage = shallowRef ( )
60
82
const func = vi . fn ( async ( ) => {
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ export function computedAsync<T>(
101
101
flush = 'pre' ,
102
102
evaluating = undefined ,
103
103
shallow = true ,
104
- onError = noop ,
104
+ onError = globalThis . reportError ?? noop ,
105
105
} = options
106
106
107
107
const started = shallowRef ( ! lazy )
You can’t perform that action at this time.
0 commit comments