mirror of
https://github.com/element-plus/element-plus.git
synced 2025-03-01 15:35:51 +08:00
refactor(components): [overlay] use JSX in Unit test (#8227)
This commit is contained in:
parent
39f122228b
commit
2f51379756
@ -1,3 +1,4 @@
|
||||
import { nextTick, ref } from 'vue'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import Overlay from '../src/overlay'
|
||||
@ -6,11 +7,7 @@ const AXIOM = 'Rem is the best girl'
|
||||
|
||||
describe('Overlay.vue', () => {
|
||||
test('render test', async () => {
|
||||
const wrapper = mount(Overlay, {
|
||||
slots: {
|
||||
default: AXIOM,
|
||||
},
|
||||
})
|
||||
const wrapper = mount(() => <Overlay>{AXIOM}</Overlay>)
|
||||
expect(wrapper.text()).toEqual(AXIOM)
|
||||
const testClass = 'test-class'
|
||||
await wrapper.setProps({
|
||||
@ -21,31 +18,28 @@ describe('Overlay.vue', () => {
|
||||
})
|
||||
|
||||
test('should emit click event', async () => {
|
||||
const wrapper = mount(Overlay, {
|
||||
slots: {
|
||||
default: AXIOM,
|
||||
},
|
||||
})
|
||||
const wrapper = mount(() => <Overlay>{AXIOM}</Overlay>)
|
||||
await wrapper.find('.el-overlay').trigger('click')
|
||||
expect(wrapper.emitted()).toBeTruthy()
|
||||
})
|
||||
|
||||
test('no mask', async () => {
|
||||
const wrapper = mount(Overlay, {
|
||||
slots: {
|
||||
default: AXIOM,
|
||||
},
|
||||
})
|
||||
const mask = ref(true)
|
||||
const wrapper = mount(() => <Overlay mask={mask.value}>{AXIOM}</Overlay>)
|
||||
|
||||
const selector = '.el-overlay'
|
||||
expect(wrapper.find(selector).exists()).toBe(true)
|
||||
|
||||
await wrapper.setProps({
|
||||
mask: false,
|
||||
})
|
||||
mask.value = false
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find(selector).exists()).toBe(false)
|
||||
await wrapper.setProps({
|
||||
mask: true,
|
||||
})
|
||||
|
||||
mask.value = true
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find(selector).exists()).toBe(true)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user