element-plus/packages/components/virtual-list/__tests__/scrollbar.spec.ts
三咲智子 55348b30b6
style: use prettier (#3228)
* style: use prettier

* style: just prettier format, no code changes

* style: eslint fix
object-shorthand, prefer-const

* style: fix no-void

* style: no-console
2021-09-04 19:29:28 +08:00

40 lines
1.1 KiB
TypeScript

import { nextTick } from '@vue/runtime-core'
import { mount } from '@vue/test-utils'
import Scrollbar from '../src/components/scrollbar'
import { ScrollbarDirKey } from '../src/defaults'
describe('virtual scrollbar', () => {
async function testInlineStyle(layout = 'vertical') {
const wrapper = mount({
template: `<scrollbar visible layout="${layout}"></scrollbar>`,
components: {
Scrollbar,
},
})
await nextTick()
const scrollbar = wrapper.findComponent(Scrollbar)
const styles = getComputedStyle(scrollbar.vm.$el)
Object.entries({
display: 'block',
position: 'absolute',
width: 'vertical' !== layout ? '100%' : '6px',
height: 'vertical' !== layout ? '6px' : 'auto',
[ScrollbarDirKey[layout]]: '2px',
right: '2px',
bottom: '2px',
'border-radius': '4px',
}).forEach(([key, value]) =>
expect(`${key}: ${styles.getPropertyValue(key)}`).toBe(`${key}: ${value}`)
)
}
it('vertical inline style', async () => {
testInlineStyle('vertical')
})
it('horizontal inline style', () => {
testInlineStyle('horizontal')
})
})