mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-02 03:08:21 +08:00
test: enable clearMocks in vitest config (#7263)
This commit is contained in:
parent
de29873f40
commit
34f6f71042
@ -114,8 +114,8 @@ describe('ElFormItem', () => {
|
||||
it('should be able to validate with callback without throwing rejection', async () => {
|
||||
const emailInput = formItemRef.value!
|
||||
const callback = vi.fn()
|
||||
expect(console.warn).toHaveBeenCalled()
|
||||
expect(emailInput.validate('', callback)).resolves.toBe(false)
|
||||
expect(console.warn).toHaveBeenCalled()
|
||||
await rAF()
|
||||
expect(callback).toHaveBeenCalled()
|
||||
})
|
||||
@ -123,8 +123,8 @@ describe('ElFormItem', () => {
|
||||
it('should emit validate event', async () => {
|
||||
const emailInput = formItemRef.value!
|
||||
const callback = vi.fn()
|
||||
expect(console.warn).toHaveBeenCalled()
|
||||
expect(emailInput.validate('', callback)).resolves.toBe(false)
|
||||
expect(console.warn).toHaveBeenCalled()
|
||||
await rAF()
|
||||
expect(findForm().emitted('validate')).toEqual([
|
||||
['email', false, 'email is required'],
|
||||
|
@ -569,8 +569,6 @@ describe('Form', () => {
|
||||
const findDomainItems = () => wrapper.findAll('.domain-item')
|
||||
|
||||
beforeEach(() => {
|
||||
onSuccess.mockClear()
|
||||
onError.mockClear()
|
||||
createComponent()
|
||||
})
|
||||
|
||||
|
@ -83,7 +83,6 @@ describe('<ElRovingFocusGroup />', () => {
|
||||
await nextTick()
|
||||
})
|
||||
afterEach(() => {
|
||||
;[onFocus, onBlur, onMousedown].forEach((f) => f.mockClear())
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
|
@ -102,7 +102,6 @@ describe('<ElRovingFocusItem />', () => {
|
||||
await nextTick()
|
||||
})
|
||||
afterEach(() => {
|
||||
;[onItemFocus, onItemShiftTab].forEach((f) => f.mockClear())
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
|
@ -5,7 +5,6 @@ import { debugWarn } from '@element-plus/utils'
|
||||
import { FORWARD_REF_INJECTION_KEY } from '@element-plus/hooks'
|
||||
import { OnlyChild } from '../src/only-child'
|
||||
import type { MountingOptions } from '@vue/test-utils'
|
||||
import type { SpyInstanceFn } from 'vitest'
|
||||
|
||||
type Slot = NonNullable<NonNullable<MountingOptions<any>['slots']>['default']>
|
||||
|
||||
@ -34,7 +33,6 @@ describe('ElOnlyChild', () => {
|
||||
let wrapper: ReturnType<typeof createComponent>
|
||||
|
||||
afterEach(() => {
|
||||
;(debugWarn as SpyInstanceFn).mockClear()
|
||||
wrapper?.unmount()
|
||||
})
|
||||
|
||||
|
@ -91,15 +91,6 @@ describe('<ElTooltipContent />', () => {
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
;[
|
||||
onOpen,
|
||||
onClose,
|
||||
onToggle,
|
||||
onShow,
|
||||
onHide,
|
||||
onBeforeShow,
|
||||
onBeforeHide,
|
||||
].forEach((fn) => fn.mockClear())
|
||||
open.value = false
|
||||
controlled.value = false
|
||||
trigger.value = 'hover'
|
||||
|
@ -7,7 +7,6 @@ import { ElPopperTrigger } from '@element-plus/components/popper'
|
||||
import Tooltip from '../src/tooltip.vue'
|
||||
|
||||
import type { VNode } from 'vue'
|
||||
import type { SpyInstanceFn } from 'vitest'
|
||||
|
||||
vi.mock('@element-plus/utils/error', () => ({
|
||||
debugWarn: vi.fn(),
|
||||
@ -32,7 +31,6 @@ describe('<ElTooltip />', () => {
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
document.body.innerHTML = ''
|
||||
;(debugWarn as SpyInstanceFn).mockClear()
|
||||
})
|
||||
|
||||
describe('rendering', () => {
|
||||
|
@ -52,7 +52,6 @@ describe('<ElTooltipTrigger />', () => {
|
||||
let wrapper: ReturnType<typeof createComponent>
|
||||
|
||||
afterEach(() => {
|
||||
;[onOpen, onClose, onToggle, onShow, onHide].forEach((fn) => fn.mockClear())
|
||||
open.value = false
|
||||
controlled.value = false
|
||||
wrapper?.unmount()
|
||||
|
@ -1,13 +1,5 @@
|
||||
import { nextTick, unref } from 'vue'
|
||||
import {
|
||||
afterAll,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
} from 'vitest'
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
||||
import makeMount from '@element-plus/test-utils/make-mount'
|
||||
import makeScroll from '@element-plus/test-utils/make-scroll'
|
||||
import setupMock from '../setup-mock'
|
||||
@ -66,10 +58,6 @@ describe('<fixed-size-grid />', () => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
onItemRendered.mockClear()
|
||||
})
|
||||
|
||||
describe('render testing', () => {
|
||||
it('should render correctly', async () => {
|
||||
const wrapper = mount()
|
||||
|
@ -1,13 +1,5 @@
|
||||
import { nextTick } from 'vue'
|
||||
import {
|
||||
afterAll,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
} from 'vitest'
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
||||
import makeMount from '@element-plus/test-utils/make-mount'
|
||||
import setupMock from '../setup-mock'
|
||||
import {
|
||||
@ -67,10 +59,6 @@ describe('<dynamic-size-list />', () => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
onItemRendered.mockClear()
|
||||
})
|
||||
|
||||
describe('render testing', () => {
|
||||
it('should render vertical list correctly', async () => {
|
||||
const wrapper = mount()
|
||||
|
@ -1,13 +1,5 @@
|
||||
import { nextTick, unref } from 'vue'
|
||||
import {
|
||||
afterAll,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
} from 'vitest'
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
||||
import makeMount from '@element-plus/test-utils/make-mount'
|
||||
import makeScroll from '@element-plus/test-utils/make-scroll'
|
||||
import setupMock from '../setup-mock'
|
||||
@ -63,10 +55,6 @@ describe('<fixed-size-grid />', () => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
onItemRendered.mockClear()
|
||||
})
|
||||
|
||||
describe('render testing', () => {
|
||||
it('should render correctly', async () => {
|
||||
const wrapper = mount()
|
||||
|
@ -1,13 +1,5 @@
|
||||
import { nextTick } from 'vue'
|
||||
import {
|
||||
afterAll,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
} from 'vitest'
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
||||
import makeMount from '@element-plus/test-utils/make-mount'
|
||||
import makeScroll from '@element-plus/test-utils/make-scroll'
|
||||
import setupMock from '../setup-mock'
|
||||
@ -65,10 +57,6 @@ describe('<fixed-size-list />', () => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
onItemRendered.mockClear()
|
||||
})
|
||||
|
||||
it('should render correctly', async () => {
|
||||
const wrapper = mount()
|
||||
|
||||
|
@ -85,8 +85,6 @@ describe('Directives.vue', () => {
|
||||
// clear the previously assigned event object
|
||||
mousedownObject = null
|
||||
mouseupObject = null
|
||||
|
||||
handler.mockClear()
|
||||
})
|
||||
test('render test', () => {
|
||||
const wrapper = _mount()
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
import sleep from '@element-plus/test-utils/sleep'
|
||||
import RepeatClick from '../repeat-click'
|
||||
|
||||
@ -19,10 +19,6 @@ const _mount = () =>
|
||||
},
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
handler.mockClear()
|
||||
})
|
||||
|
||||
describe('Directives.vue', () => {
|
||||
test('Click test', async () => {
|
||||
const wrapper = _mount()
|
||||
|
@ -52,8 +52,6 @@ describe('use-model-toggle', () => {
|
||||
beforeEach(() => {
|
||||
flag = true
|
||||
wrapper = mount(Comp)
|
||||
onShow.mockClear()
|
||||
onHide.mockClear()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -1,13 +1,5 @@
|
||||
import { ref } from 'vue'
|
||||
import {
|
||||
afterAll,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
} from 'vitest'
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
||||
import triggerEvent from '@element-plus/test-utils/trigger-event'
|
||||
import { usePreventGlobal } from '../use-prevent-global'
|
||||
|
||||
@ -18,10 +10,6 @@ describe('usePreventGlobal', () => {
|
||||
document.body.addEventListener(evtName, evtHandler)
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
evtHandler.mockClear()
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
document.body.removeEventListener(evtName, evtHandler)
|
||||
})
|
||||
|
@ -9,6 +9,7 @@ export default defineConfig({
|
||||
disabled: true,
|
||||
},
|
||||
test: {
|
||||
clearMocks: true,
|
||||
environment: 'jsdom',
|
||||
setupFiles: ['./vitest.setup.ts'],
|
||||
transformMode: {
|
||||
|
Loading…
Reference in New Issue
Block a user