mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
test(components): [avatar, image] improve image load test stability (#21762)
* test(components): [avatar] improve fallback slot test stability * test: improve image test
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { markRaw, nextTick } from 'vue'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import { User } from '@element-plus/icons-vue'
|
||||
import {
|
||||
@@ -54,7 +54,12 @@ describe('Avatar.vue', () => {
|
||||
)
|
||||
|
||||
await nextTick()
|
||||
wrapper.emitted('error') && expect(wrapper.emitted('error')).toBeDefined()
|
||||
const img = wrapper.find('img')
|
||||
if (img.exists()) {
|
||||
await img.trigger('error')
|
||||
}
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('error')).toBeDefined()
|
||||
await nextTick()
|
||||
expect(wrapper.text()).toBe('fallback')
|
||||
expect(wrapper.find('img').exists()).toBe(false)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { nextTick } from 'vue'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
import {
|
||||
IMAGE_FAIL,
|
||||
@@ -271,12 +271,19 @@ describe('Image.vue', () => {
|
||||
src: IMAGE_FAIL,
|
||||
},
|
||||
})
|
||||
wrapper.setProps({
|
||||
src: IMAGE_SUCCESS,
|
||||
})
|
||||
expect(wrapper.find('.el-image__placeholder').exists()).toBe(true)
|
||||
await doubleWait()
|
||||
expect(wrapper.emitted('error')).toBeUndefined()
|
||||
await flushPromises()
|
||||
const errorCountBefore = wrapper.emitted('error')?.length || 0
|
||||
|
||||
await wrapper.setProps({ src: IMAGE_SUCCESS })
|
||||
await nextTick()
|
||||
const img = wrapper.find('img')
|
||||
if (img.exists()) {
|
||||
await img.trigger('load')
|
||||
}
|
||||
await flushPromises()
|
||||
// expect no new error event to be emitted
|
||||
expect(wrapper.emitted('error')?.length).toBe(errorCountBefore)
|
||||
|
||||
expect(wrapper.find('.el-image__inner').exists()).toBe(true)
|
||||
expect(wrapper.find('img').exists()).toBe(true)
|
||||
expect(wrapper.find('.el-image__placeholder').exists()).toBe(false)
|
||||
|
||||
Reference in New Issue
Block a user