test: add affix unit test

pull/22/head
tangjinzhou 7 years ago
parent f01840f307
commit 09e25a2889

@ -0,0 +1,71 @@
import Affix from '..'
import Button from '../../button'
import { mount } from '@vue/test-utils'
const events = {}
const AffixMounter = {
mounted () {
this.$refs.container.scrollTop = 100
this.$refs.container.addEventListener = jest.fn().mockImplementation((event, cb) => {
events[event] = cb
})
},
methods: {
getTarget () {
return this.$refs.container
},
},
render () {
return (
<div
style={{
height: '100px',
overflowY: 'scroll',
}}
ref='container'
>
<div
className='background'
style={{
paddingTop: '60px',
height: '300px',
}}
>
<Affix
target={() => this.$refs.container}
ref='affix'
>
<Button type='primary' >
Fixed at the top of container
</Button>
</Affix>
</div>
</div>
)
},
}
describe('Affix Render', () => {
beforeAll(() => {
jest.useFakeTimers()
})
afterAll(() => {
jest.useRealTimers()
})
it('Affix render perfectly', () => {
const wrapper = mount(AffixMounter, { attachToDocument: true })
jest.runAllTimers()
wrapper.vm.$refs.affix.$refs.fixedNode.parentNode.getBoundingClientRect = jest.fn(() => {
return {
bottom: 100, height: 28, left: 0, right: 0, top: -50, width: 195,
}
})
events.scroll({
type: 'scroll',
})
jest.runAllTimers()
expect(wrapper.vm.$refs.affix.affixStyle).not.toBe(null)
})
})

@ -1,6 +1,4 @@
import Vue from 'vue'
import antd from 'vue-antd-ui'
Vue.use(antd)
/* eslint-disable global-require */
if (typeof window !== 'undefined') {
global.window.resizeTo = (width, height) => {

@ -2,6 +2,9 @@ import glob from 'glob'
import { renderToString } from '@vue/server-test-utils'
import MockDate from 'mockdate'
import moment from 'moment'
import Vue from 'vue'
import antd from 'vue-antd-ui'
Vue.use(antd)
export default function demoTest (component, options = {}) {
const files = glob.sync(`./components/${component}/demo/*.md`)

Loading…
Cancel
Save