Skip to content

Commit

Permalink
Destroy PerfectScrollbar object and clear reference to HTMLElement af…
Browse files Browse the repository at this point in the history
…ter component destroy
  • Loading branch information
mercs600 committed Oct 12, 2018
1 parent 4d28296 commit 64985bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Scrollbar.js
Expand Up @@ -26,11 +26,20 @@ export default {
updated () {
this.update()
},
beforeDestroy () {
this.destroy()
},
methods: {
update () {
if (this.ps) {
this.ps.update()
}
},
destroy () {
if (this.ps) {
this.ps.destroy()
this.ps = null
}
}
},
render (h) {
Expand Down
17 changes: 17 additions & 0 deletions test/unit/Scrollbar.spec.js
Expand Up @@ -19,4 +19,21 @@ describe('Scrollbar.vue', () => {
})
expect(wrapper.find('.ps').classes('ps--active-y')).to.be.false
})

it('this.ps should be null after destroy', () => {
const wrapper = shallowMount(Scrollbar, {
attachToDocument: true
})
wrapper.destroy()
expect(wrapper.vm.ps).to.be.null
})

it('Component should remove reference do HTMLElement after destroy', () => {
const wrapper = shallowMount(Scrollbar, {
attachToDocument: true
})
let psObject = wrapper.vm.ps
wrapper.destroy()
expect(psObject.element).to.be.null
})
})

0 comments on commit 64985bf

Please sign in to comment.