Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkjaergaard committed Mar 5, 2020
1 parent de76dbf commit 283c809
Show file tree
Hide file tree
Showing 3 changed files with 2,178 additions and 886 deletions.
27 changes: 27 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,33 @@ test('It should disconnect the IntersectionObserver when the component is destro
vm.$destroy()
expect(spy.destroyed).toHaveBeenCalledTimes(1)
expect(spy.disconnect).toHaveBeenCalledTimes(1)
spy.disconnect.mockClear()
})

test('It should emit event when component is destroyed', async () => {
const mockedIntersect = Object.assign({}, Intersect)
const onDestroy = jest.fn()

const spy = {
destroyed: jest.spyOn(mockedIntersect, 'destroyed'),
disconnect: jest.spyOn(global.IntersectionObserver.prototype, 'disconnect')
}

const vm = new Vue({
template: `<intersect @destroyed="onDestroy"><div></div></intersect>`,
components: {Intersect: mockedIntersect},
methods: {
onDestroy
}
}).$mount()

await vm.$nextTick()

vm.$destroy()

expect(spy.destroyed).toHaveBeenCalledTimes(1)
expect(spy.disconnect).toHaveBeenCalledTimes(1)
expect(onDestroy).toHaveBeenCalledTimes(1)
})

test('It should warn when no child component is defined', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
})
},
destroyed () {
this.$emit('destroyed');
this.$emit('destroyed')
this.observer.disconnect()
},
render () {
Expand Down
Loading

0 comments on commit 283c809

Please sign in to comment.