element-plus/packages/components/teleport/__tests__/teleport.test.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-11-03 17:42:05 +08:00
import { mount } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
2021-11-03 17:42:05 +08:00
import Teleport from '../src/teleport.vue'
import type { VueWrapper } from '@vue/test-utils'
import type { TeleportInstance } from '../src/teleport'
2021-11-03 17:42:05 +08:00
const AXIOM = 'rem is the best girl'
describe('ElTelport', () => {
let wrapper: VueWrapper<TeleportInstance>
2021-11-03 17:42:05 +08:00
beforeEach(() => {
wrapper = mount(Teleport, {
slots: { default: () => AXIOM },
})
})
afterEach(() => {
wrapper.unmount()
})
it('should render slot correctly', () => {
expect(wrapper.text()).toBe('')
expect(document.body.textContent).toBe(AXIOM)
expect(wrapper.vm.containerRef).toBeDefined()
})
describe('props', () => {
it('should be able to set customized style', async () => {
const style = {
color: 'red',
}
await wrapper.setProps({ style })
expect(getComputedStyle(wrapper.vm?.containerRef!).color).toBe(
style.color
)
2021-11-03 17:42:05 +08:00
})
it('should be able to set z-index', async () => {
const zIndex = '10000'
await wrapper.setProps({ zIndex })
expect(getComputedStyle(wrapper.vm?.containerRef!).zIndex).toBe(zIndex)
2021-11-03 17:42:05 +08:00
})
})
})