File tree 2 files changed +37
-4
lines changed
test/unit/modules/observer
2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -69,10 +69,14 @@ function flushSchedulerQueue () {
69
69
}
70
70
}
71
71
72
+ // reset scheduler before updated hook called
73
+ const oldQueue = queue . slice ( )
74
+ resetSchedulerState ( )
75
+
72
76
// call updated hooks
73
- index = queue . length
77
+ index = oldQueue . length
74
78
while ( index -- ) {
75
- watcher = queue [ index ]
79
+ watcher = oldQueue [ index ]
76
80
vm = watcher . vm
77
81
if ( vm . _watcher === watcher && vm . _isMounted ) {
78
82
callHook ( vm , 'updated' )
@@ -84,8 +88,6 @@ function flushSchedulerQueue () {
84
88
if ( devtools && config . devtools ) {
85
89
devtools . emit ( 'flush' )
86
90
}
87
-
88
- resetSchedulerState ( )
89
91
}
90
92
91
93
/**
Original file line number Diff line number Diff line change @@ -144,4 +144,35 @@ describe('Scheduler', () => {
144
144
expect ( callOrder ) . toEqual ( [ 1 , 2 , 3 ] )
145
145
} ) . then ( done )
146
146
} )
147
+
148
+ // Github issue #5191
149
+ it ( 'emit should work when updated hook called' , done => {
150
+ const el = document . createElement ( 'div' )
151
+ const vm = new Vue ( {
152
+ template : `<div><child @change="bar" :foo="foo"></child></div>` ,
153
+ data : {
154
+ foo : 0
155
+ } ,
156
+ methods : {
157
+ bar : spy
158
+ } ,
159
+ components : {
160
+ child : {
161
+ template : `<div>{{foo}}</div>` ,
162
+ props : [ 'foo' ] ,
163
+ updated ( ) {
164
+ this . $emit ( 'change' )
165
+ }
166
+ }
167
+ }
168
+ } ) . $mount ( el )
169
+ vm . $nextTick ( ( ) => {
170
+ vm . foo = 1
171
+ vm . $nextTick ( ( ) => {
172
+ expect ( vm . $el . innerHTML ) . toBe ( '<div>1</div>' )
173
+ expect ( spy ) . toHaveBeenCalled ( )
174
+ done ( )
175
+ } )
176
+ } )
177
+ } )
147
178
} )
You can’t perform that action at this time.
0 commit comments