fix(test-utils): revert image patch

This commit is contained in:
HerringtonDarkholme
2020-09-07 17:41:18 +08:00
committed by jeremywu
parent 3b5c53994e
commit 9cd4de7e19
3 changed files with 16 additions and 9 deletions

View File

@@ -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)

View File

@@ -12,7 +12,7 @@ async function doubleWait() {
}
describe('Image.vue', () => {
beforeAll(mockImageEvent)
mockImageEvent()
test('render test', () => {
const wrapper = mount(Image)

View File

@@ -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)
})
}