Skip to content

Commit 283c809

Browse files
committed
Add tests
1 parent de76dbf commit 283c809

File tree

3 files changed

+2178
-886
lines changed

3 files changed

+2178
-886
lines changed

__tests__/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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

170197
test('It should warn when no child component is defined', async () => {

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 () {

0 commit comments

Comments
 (0)