fix: vitest

This commit is contained in:
三咲智子
2022-04-12 01:10:25 +08:00
parent ef9038ad71
commit b2bfb6f159
6 changed files with 15 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
import { defineComponent } from 'vue'
import { mount } from '@vue/test-utils'
import { afterEach, describe, expect, fn, it, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { useAttrs } from '../use-attrs'
const CLASS = 'a'
@@ -9,7 +9,7 @@ const TEST_KEY = 'test'
const TEST_VALUE = 'fake'
const ANOTHER_TEST_VALUE = 'fake1'
const handleClick = fn()
const handleClick = vi.fn()
const genComp = (
inheritAttrs = true,

View File

@@ -1,6 +1,6 @@
import { computed, defineComponent, nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { afterEach, describe, expect, fn, it, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { debugWarn } from '@element-plus/utils'
import { useDeprecated } from '../use-deprecated'
@@ -9,7 +9,7 @@ const AXIOM = 'Rem is the best girl'
vi.mock('@element-plus/utils/error', async () => {
return {
...(await vi.importActual<any>('@element-plus/utils/error')),
debugWarn: fn(),
debugWarn: vi.fn(),
}
})

View File

@@ -1,12 +1,12 @@
import { nextTick, ref } from 'vue'
import { describe, expect, fn, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import { EVENT_CODE } from '@element-plus/constants'
import { useModal } from '../use-modal'
describe('useModal', () => {
it('should work when ref value changed', async () => {
const visible = ref(false)
const handleClose = fn()
const handleClose = vi.fn()
useModal(
{

View File

@@ -1,14 +1,14 @@
import { defineComponent, nextTick, reactive, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, fn, it } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { useModelToggle, useModelToggleProps } from '../use-model-toggle'
import type { VueWrapper } from '@vue/test-utils'
const AXIOM = 'Rem is the best girl'
const onShow = fn()
const onHide = fn()
const onShow = vi.fn()
const onHide = vi.fn()
let flag = true
const shouldProceed = () => flag

View File

@@ -5,15 +5,15 @@ import {
beforeEach,
describe,
expect,
fn,
it,
vi,
} from 'vitest'
import triggerEvent from '@element-plus/test-utils/trigger-event'
import { usePreventGlobal } from '../use-prevent-global'
describe('usePreventGlobal', () => {
const evtName = 'keydown'
const evtHandler = fn()
const evtHandler = vi.fn()
beforeAll(() => {
document.body.addEventListener(evtName, evtHandler)
})
@@ -28,7 +28,7 @@ describe('usePreventGlobal', () => {
it('should prevent global event from happening', () => {
const visible = ref(true)
const evt2Trigger = fn().mockReturnValue(true)
const evt2Trigger = vi.fn().mockReturnValue(true)
usePreventGlobal(visible, evtName, evt2Trigger)
triggerEvent(document.body, evtName)
@@ -40,7 +40,7 @@ describe('usePreventGlobal', () => {
it('should not prevent global event from happening', () => {
const visible = ref(true)
const evt2Trigger = fn().mockReturnValue(false)
const evt2Trigger = vi.fn().mockReturnValue(false)
usePreventGlobal(visible, evtName, evt2Trigger)
triggerEvent(document.body, evtName)

View File

@@ -1,4 +1,4 @@
import { describe, expect, it, spyOn } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import { isFocusable, triggerEvent } from '../..'
const CE = (tag: string) => document.createElement(tag)
@@ -7,7 +7,7 @@ describe('Aria Utils', () => {
describe('Trigger Event', () => {
it('Util trigger event to trigger event correctly', () => {
const div = document.createElement('div')
spyOn(div, 'dispatchEvent')
vi.spyOn(div, 'dispatchEvent')
const eventName = 'click'
triggerEvent(div, eventName)
expect(div.dispatchEvent).toHaveBeenCalled()