File tree Expand file tree Collapse file tree 3 files changed +30
-17
lines changed Expand file tree Collapse file tree 3 files changed +30
-17
lines changed Original file line number Diff line number Diff line change @@ -132,10 +132,14 @@ class Store {
132
132
if ( ! isPromise ( res ) ) {
133
133
res = Promise . resolve ( res )
134
134
}
135
- return res . catch ( err => {
136
- console . error ( `[vuex] error in Promise returned from action "${ type } ":` )
137
- console . error ( err )
138
- } )
135
+ if ( store . _devtoolHook ) {
136
+ return res . catch ( err => {
137
+ store . _devtoolHook . emit ( 'vuex:error' , err )
138
+ throw err
139
+ } )
140
+ } else {
141
+ return res
142
+ }
139
143
} )
140
144
}
141
145
Original file line number Diff line number Diff line change 1
- const hook =
1
+ const devtoolHook =
2
2
typeof window !== 'undefined' &&
3
3
window . __VUE_DEVTOOLS_GLOBAL_HOOK__
4
4
5
5
export default function devtoolPlugin ( store ) {
6
- if ( ! hook ) return
6
+ if ( ! devtoolHook ) return
7
7
8
- hook . emit ( 'vuex:init' , store )
8
+ store . _devtoolHook = devtoolHook
9
9
10
- hook . on ( 'vuex:travel-to-state' , targetState => {
10
+ devtoolHook . emit ( 'vuex:init' , store )
11
+
12
+ devtoolHook . on ( 'vuex:travel-to-state' , targetState => {
11
13
store . replaceState ( targetState )
12
14
} )
13
15
14
16
store . subscribe ( ( mutation , state ) => {
15
- hook . emit ( 'vuex:mutation' , mutation , state )
17
+ devtoolHook . emit ( 'vuex:mutation' , mutation , state )
16
18
} )
17
19
}
Original file line number Diff line number Diff line change @@ -108,22 +108,29 @@ describe('Vuex', () => {
108
108
} )
109
109
} )
110
110
111
- it ( 'capturing action Promise errors' , done => {
112
- const spy = sinon . spy ( console , 'error' )
111
+ it ( 'detecting action Promise errors' , done => {
113
112
const store = new Vuex . Store ( {
114
113
actions : {
115
114
[ TEST ] ( ) {
116
115
return new Promise ( ( resolve , reject ) => {
117
- reject ( new Error ( ) )
116
+ reject ( 'no' )
118
117
} )
119
118
}
120
119
}
121
120
} )
122
- store . dispatch ( TEST ) . then ( ( ) => {
123
- expect ( spy ) . to . have . been . calledWith ( `[vuex] error in Promise returned from action "${ TEST } ":` )
124
- spy . restore ( )
125
- done ( )
126
- } )
121
+ const spy = sinon . spy ( )
122
+ store . _devtoolHook = {
123
+ emit : spy
124
+ }
125
+ const thenSpy = sinon . spy ( )
126
+ store . dispatch ( TEST )
127
+ . then ( thenSpy )
128
+ . catch ( err => {
129
+ expect ( thenSpy ) . not . to . have . been . called
130
+ expect ( err ) . to . equal ( 'no' )
131
+ expect ( spy ) . to . have . been . calledWith ( 'vuex:error' , 'no' )
132
+ done ( )
133
+ } )
127
134
} )
128
135
129
136
it ( 'getters' , ( ) => {
You can’t perform that action at this time.
0 commit comments