File tree Expand file tree Collapse file tree 3 files changed +2178
-886
lines changed Expand file tree Collapse file tree 3 files changed +2178
-886
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,33 @@ test('It should disconnect the IntersectionObserver when the component is destro
165165 vm . $destroy ( )
166166 expect ( spy . destroyed ) . toHaveBeenCalledTimes ( 1 )
167167 expect ( spy . disconnect ) . toHaveBeenCalledTimes ( 1 )
168+ spy . disconnect . mockClear ( )
169+ } )
170+
171+ test ( 'It should emit event when component is destroyed' , async ( ) => {
172+ const mockedIntersect = Object . assign ( { } , Intersect )
173+ const onDestroy = jest . fn ( )
174+
175+ const spy = {
176+ destroyed : jest . spyOn ( mockedIntersect , 'destroyed' ) ,
177+ disconnect : jest . spyOn ( global . IntersectionObserver . prototype , 'disconnect' )
178+ }
179+
180+ const vm = new Vue ( {
181+ template : `<intersect @destroyed="onDestroy"><div></div></intersect>` ,
182+ components : { Intersect : mockedIntersect } ,
183+ methods : {
184+ onDestroy
185+ }
186+ } ) . $mount ( )
187+
188+ await vm . $nextTick ( )
189+
190+ vm . $destroy ( )
191+
192+ expect ( spy . destroyed ) . toHaveBeenCalledTimes ( 1 )
193+ expect ( spy . disconnect ) . toHaveBeenCalledTimes ( 1 )
194+ expect ( onDestroy ) . toHaveBeenCalledTimes ( 1 )
168195} )
169196
170197test ( 'It should warn when no child component is defined' , async ( ) => {
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ export default {
5353 } )
5454 } ,
5555 destroyed ( ) {
56- this . $emit ( 'destroyed' ) ;
56+ this . $emit ( 'destroyed' )
5757 this . observer . disconnect ( )
5858 } ,
5959 render ( ) {
You can’t perform that action at this time.
0 commit comments