Skip to content

Commit

Permalink
test: use explicit import from vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 18, 2023
1 parent a96aa5d commit 2e16215
Show file tree
Hide file tree
Showing 152 changed files with 347 additions and 217 deletions.
1 change: 1 addition & 0 deletions packages/.test/mockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { setupServer } from 'msw/node'
import type { RestContext, RestRequest } from 'msw'
import { rest } from 'msw'
import { afterAll, afterEach, beforeAll } from 'vitest'

const defaultJsonMessage = { hello: 'world' }
const defaultTextMessage = 'Hello World'
Expand Down
2 changes: 2 additions & 0 deletions packages/.test/polyfillMatchMedia.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { vi } from 'vitest'

window.matchMedia = window.matchMedia || vi.fn().mockImplementation((query) => {
return {
matches: false,
Expand Down
2 changes: 2 additions & 0 deletions packages/.test/retry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { vi } from 'vitest'

// Like `until` but works off of any assertion, not application code.
export function retry(assertion: Function, { interval = 1, timeout = 100 } = {}) {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/.test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Vue2, install, isVue2 } from 'vue-demi'
import { beforeAll, beforeEach } from 'vitest'
import './polyfillFetch'
import './polyfillPointerEvents'
import './polyfillIndexedDb'
import './polyfillMatchMedia'
import { beforeAll, beforeEach } from 'vitest'

function setupVueSwitch() {
if (isVue2) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/_template/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'vitest'
import { useCounter } from '.'

describe('useCounter', () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/core/computedAsync/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, nextTick, ref } from 'vue-demi'
import { promiseTimeout } from '@vueuse/shared'
import { describe, expect, it, vi } from 'vitest'
import { asyncComputed, computedAsync } from '.'

describe('computed', () => {
Expand Down Expand Up @@ -153,7 +154,7 @@ describe('computedAsync', () => {
expect(double.value).toBe(8)
})

test('evaluating works', async () => {
it('evaluating works', async () => {
const evaluating = ref(false)

const data = computedAsync(() =>
Expand All @@ -171,7 +172,7 @@ describe('computedAsync', () => {
expect(data.value).toBe('data')
})

test('triggers', async () => {
it('triggers', async () => {
const counter = ref(1)
const double = computedAsync(() => {
const result = counter.value * 2
Expand Down Expand Up @@ -199,7 +200,7 @@ describe('computedAsync', () => {
expect(other.value).toBe(5)
})

test('cancel is called', async () => {
it('cancel is called', async () => {
const onCancel = vi.fn()
const evaluating = ref(false)

Expand Down Expand Up @@ -235,7 +236,7 @@ describe('computedAsync', () => {
expect(uppercase.value).toBe('FINAL')
})

test('cancel is called for lazy', async () => {
it('cancel is called for lazy', async () => {
const onCancel = vi.fn()

const data = ref('initial')
Expand Down
2 changes: 1 addition & 1 deletion packages/core/computedInject/demoReceiver.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { InjectionKey, Ref } from 'vue-demi'
import { defineComponent, ref } from 'vue-demi'
import { computedInject } from './index'
import { computedInject } from '.'
type OptionsRef = Ref<{ key: number; value: string }[]>
Expand Down
1 change: 1 addition & 0 deletions packages/core/computedInject/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ref } from 'vue-demi'
import { describe, expect, it } from 'vitest'
import { Key, useInjectedSetup } from '../../.test'
import { computedInject } from '.'

Expand Down
1 change: 1 addition & 0 deletions packages/core/createUnrefFn/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'vitest'
import { createUnrefFn } from '.'

describe('createUnrefFn', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/onClickOutside/directive.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineComponent } from 'vue-demi'
import { beforeEach, describe, expect, it } from 'vitest'
import type { VueWrapper } from '@vue/test-utils'
import { mount } from '@vue/test-utils'

Expand Down
2 changes: 1 addition & 1 deletion packages/core/onKeyStroke/directive.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent } from 'vue-demi'
import type { VueWrapper } from '@vue/test-utils'
import { mount } from '@vue/test-utils'

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { vOnKeyStroke } from './directive'
import type { OnKeyStrokeOptions } from '.'

Expand Down
2 changes: 1 addition & 1 deletion packages/core/onKeyStroke/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { Ref } from 'vue-demi'
import { ref } from 'vue-demi'
import type { KeyStrokeEventName } from '.'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/onLongPress/directive.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, isVue3 } from 'vue-demi'

import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { VueWrapper } from '@vue/test-utils'
import { mount } from '@vue/test-utils'
import { promiseTimeout } from '@vueuse/shared'
Expand Down
1 change: 1 addition & 0 deletions packages/core/onLongPress/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { promiseTimeout } from '@vueuse/shared'
import type { Ref } from 'vue-demi'
import { ref } from 'vue-demi'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useEventListener } from '../useEventListener'
import { onLongPress } from '.'

Expand Down
1 change: 1 addition & 0 deletions packages/core/templateRef/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineComponent, h, nextTick, ref } from 'vue-demi'
import { describe, expect, it } from 'vitest'
import { mount } from '../../.test'
import { templateRef } from '.'

Expand Down
1 change: 1 addition & 0 deletions packages/core/useActiveElement/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { useActiveElement } from '.'

describe('useActiveElement', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/useAnimate/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { shallowRef } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { useAnimate } from '.'

describe('useAnimate', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/useAsyncQueue/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, vi } from 'vitest'
import { retry } from '../../.test'
import { useAsyncQueue } from '.'

Expand Down
3 changes: 2 additions & 1 deletion packages/core/useAsyncState/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { promiseTimeout } from '@vueuse/shared'
import { useAsyncState } from '../useAsyncState'
import { describe, expect, it, vi } from 'vitest'
import { useAsyncState } from '.'

describe('useAsyncState', () => {
it('should be defined', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/useBase64/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Buffer } from 'node:buffer'
import { useBase64 } from '@vueuse/core'
import { describe, expect } from 'vitest'
import { describe, expect, it } from 'vitest'
import { useBase64 } from '.'

function decode(encoded: string) {
const decodedStr = Buffer.from(encoded.split(',')[1], 'base64').toString('utf-8')
Expand Down
1 change: 1 addition & 0 deletions packages/core/useBluetooth/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'vitest'
import { useBluetooth } from '.'

describe('useBluetooth', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/useCached/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ref } from 'vue-demi'
import { describe, expect, it } from 'vitest'
import { nextTwoTick } from '../../.test'
import { useCached } from '.'

Expand Down
2 changes: 1 addition & 1 deletion packages/core/useCloned/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCloned } from '@vueuse/core'
import { expect } from 'vitest'
import { describe, expect, it } from 'vitest'
import { nextTick, ref } from 'vue-demi'

describe('useCloned', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/useColorMode/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { nextTwoTick } from 'packages/.test'
import { expect, vi } from 'vitest'
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue-demi'
import { usePreferredDark } from '../usePreferredDark'
import { useColorMode } from './index'
import { useColorMode } from '.'

describe('useColorMode', () => {
const storageKey = 'vueuse-color-scheme'
Expand Down
1 change: 1 addition & 0 deletions packages/core/useConfirmDialog/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { nextTick, ref } from 'vue-demi'
import { describe, expect, it } from 'vitest'
import { useConfirmDialog } from '.'

describe('useConfirmDialog', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/useCssVar/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defaultWindow } from '@vueuse/core'
import { nextTick } from 'vue-demi'
import { describe, expect, it } from 'vitest'
import { useCssVar } from '.'

describe('useCssVar', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/useCycleList/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ref } from 'vue-demi'
import { describe, expect, it } from 'vitest'
import { useCycleList } from '.'

describe('useCycleList', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/useDebouncedRefHistory/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { nextTick, ref } from 'vue-demi'
import { promiseTimeout } from '@vueuse/shared'
import { describe, expect, it } from 'vitest'
import { useDebouncedRefHistory } from '.'

describe('useDebouncedRefHistory', () => {
test('Once the ref\'s value has changed and some time has passed, ensure the snapshot is updated', async () => {
it('Once the ref\'s value has changed and some time has passed, ensure the snapshot is updated', async () => {
const v = ref(0)

const { history } = useDebouncedRefHistory(v, { debounce: 10 })
Expand All @@ -17,7 +18,7 @@ describe('useDebouncedRefHistory', () => {
expect(history.value[0].snapshot).toBe(100)
})

test('when debounce is undefined', async () => {
it('when debounce is undefined', async () => {
const v = ref(0)

const { history } = useDebouncedRefHistory(v, { deep: false })
Expand Down
2 changes: 1 addition & 1 deletion packages/core/useElementHover/directive.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent } from 'vue-demi'
import type { VueWrapper } from '@vue/test-utils'
import { mount } from '@vue/test-utils'

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { vElementHover } from './directive'

const App = defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/useElementSize/directive.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent } from 'vue-demi'
import type { VueWrapper } from '@vue/test-utils'
import { mount } from '@vue/test-utils'

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { vElementSize } from './directive'

const App = defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/useElementVisibility/directive.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent } from 'vue-demi'
import type { VueWrapper } from '@vue/test-utils'
import { mount } from '@vue/test-utils'

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { vElementVisibility } from './directive'
import type { UseElementVisibilityOptions } from '.'

Expand Down
1 change: 1 addition & 0 deletions packages/core/useElementVisibility/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { useElementVisibility } from '.'

describe('useElementVisibility', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/useEventBus/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { nextTick } from 'vue-demi'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useCounter } from '../../shared/useCounter'
import { useSetup } from '../../.test'
import { events } from './internal'
Expand Down
1 change: 1 addition & 0 deletions packages/core/useEventListener/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Fn } from '@vueuse/shared'
import type { SpyInstance } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { noop } from '@vueuse/shared'
import { isVue2 } from 'vue-demi'
import type { Ref } from 'vue'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/useFavicon/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect } from 'vitest'
import { describe, expect, it } from 'vitest'
import { computed, ref } from 'vue'
import { useFavicon } from '.'

Expand Down

0 comments on commit 2e16215

Please sign in to comment.