Add tests for to-top-button.vue

This commit is contained in:
Phan An 2017-12-29 15:23:00 +01:00
parent 5ca8d90a82
commit ff37d7aaaf
2 changed files with 13 additions and 1 deletions

View file

@ -27,7 +27,7 @@ export default {
},
mounted () {
this.$el.parentNode.addEventListener('scroll', e => {
this.$el.parentNode && this.$el.parentNode.addEventListener('scroll', e => {
this.showing = e.target.scrollTop > 64
})
}

View file

@ -0,0 +1,12 @@
import Component from '@/components/shared/to-top-button.vue'
import { $ } from '@/utils'
describe('components/shared/to-top-button', () => {
it('scrolls to top', () => {
const scrollToStub = sinon.stub($, 'scrollTo')
const wrapper = shallow(Component)
wrapper.find('button').trigger('click')
scrollToStub.called.should.be.true
scrollToStub.restore()
})
})