File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
test/unit/features/options Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -196,7 +196,7 @@ export function mountComponent (
196196 // component's mounted hook), which relies on vm._watcher being already defined
197197 new Watcher ( vm , updateComponent , noop , {
198198 before ( ) {
199- if ( vm . _isMounted ) {
199+ if ( vm . _isMounted && ! vm . _isDestroyed ) {
200200 callHook ( vm , 'beforeUpdate' )
201201 }
202202 }
Original file line number Diff line number Diff line change @@ -152,6 +152,43 @@ describe('Options lifecycle hooks', () => {
152152 expect ( vm . $el . textContent ) . toBe ( 'bar!' )
153153 } ) . then ( done )
154154 } )
155+
156+ // #8076
157+ it ( 'should not be called after destroy' , done => {
158+ const beforeUpdate = jasmine . createSpy ( 'beforeUpdate' )
159+ const destroyed = jasmine . createSpy ( 'destroyed' )
160+
161+ Vue . component ( 'todo' , {
162+ template : '<div>{{todo.done}}</div>' ,
163+ props : [ 'todo' ] ,
164+ destroyed,
165+ beforeUpdate
166+ } )
167+
168+ const vm = new Vue ( {
169+ template : `
170+ <div>
171+ <todo v-for="t in pendingTodos" :todo="t" :key="t.id"></todo>
172+ </div>
173+ ` ,
174+ data ( ) {
175+ return {
176+ todos : [ { id : 1 , done : false } ]
177+ }
178+ } ,
179+ computed : {
180+ pendingTodos ( ) {
181+ return this . todos . filter ( t => ! t . done )
182+ }
183+ }
184+ } ) . $mount ( )
185+
186+ vm . todos [ 0 ] . done = true
187+ waitForUpdate ( ( ) => {
188+ expect ( destroyed ) . toHaveBeenCalled ( )
189+ expect ( beforeUpdate ) . not . toHaveBeenCalled ( )
190+ } ) . then ( done )
191+ } )
155192 } )
156193
157194 describe ( 'updated' , ( ) => {
You can’t perform that action at this time.
0 commit comments