mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(test-utils): revert image patch
This commit is contained in:
committed by
jeremywu
parent
3b5c53994e
commit
9cd4de7e19
@@ -4,7 +4,7 @@ import Avatar from '../src/index.vue'
|
||||
import { IMAGE_SUCCESS, IMAGE_FAIL, mockImageEvent } from '@element-plus/test-utils'
|
||||
|
||||
describe('Avatar.vue', () => {
|
||||
beforeAll(mockImageEvent)
|
||||
mockImageEvent()
|
||||
|
||||
test('render test', () => {
|
||||
const wrapper = mount(Avatar)
|
||||
|
||||
@@ -12,7 +12,7 @@ async function doubleWait() {
|
||||
}
|
||||
|
||||
describe('Image.vue', () => {
|
||||
beforeAll(mockImageEvent)
|
||||
mockImageEvent()
|
||||
|
||||
test('render test', () => {
|
||||
const wrapper = mount(Image)
|
||||
|
||||
@@ -5,12 +5,19 @@ export const IMAGE_SUCCESS = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAA
|
||||
export const IMAGE_FAIL = 'data:image/png;base64,fail'
|
||||
|
||||
export function mockImageEvent() {
|
||||
Object.defineProperty(global.Image.prototype, 'src', {
|
||||
set(src) {
|
||||
const evt = !src || src === IMAGE_FAIL
|
||||
? 'error' : 'load'
|
||||
const event = new Event(evt)
|
||||
nextTick(() => this.dispatchEvent(event))
|
||||
},
|
||||
const imageProto = global.Image.prototype
|
||||
const oldDescriptor = Object.getOwnPropertyDescriptor(imageProto, 'src')
|
||||
beforeAll(() => {
|
||||
Object.defineProperty(imageProto, 'src', {
|
||||
set(src) {
|
||||
const evt = !src || src === IMAGE_FAIL
|
||||
? 'error' : 'load'
|
||||
const event = new Event(evt)
|
||||
nextTick(() => this.dispatchEvent(event))
|
||||
},
|
||||
})
|
||||
})
|
||||
afterAll(() => {
|
||||
Object.defineProperty(imageProto, 'src', oldDescriptor)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user