Skip to content

Commit

Permalink
test: add vue suspense test (vitest-dev#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored and JakeGinnivan committed Jan 8, 2022
1 parent 0c14b1a commit 40b77bb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/vue/components/AsyncComp.vue
@@ -0,0 +1,9 @@
<script setup lang="ts">
const props = defineProps<{ promise: Promise<void> }>()
await props.promise
</script>

<template>
<div>resolved</div>
</template>
14 changes: 14 additions & 0 deletions test/vue/components/AsyncWrapper.vue
@@ -0,0 +1,14 @@
<script setup lang="ts">
import AsyncComp from './AsyncComp.vue'
defineProps<{ promise: Promise<void> }>()
</script>

<template>
<Suspense>
<AsyncComp :promise="promise" />
<template #fallback>
fallback
</template>
</Suspense>
</template>
29 changes: 29 additions & 0 deletions test/vue/test/async.test.ts
@@ -0,0 +1,29 @@
import { nextTick } from 'vue'
import { flushPromises, mount } from '@vue/test-utils'
import AsyncWrapper from '../components/AsyncWrapper.vue'

test('async component with suspense', async() => {
expect(AsyncWrapper).toBeTruthy()

let resolve: Function
// eslint-disable-next-line promise/param-names
const promise = new Promise(_resolve => resolve = _resolve)
const wrapper = mount(AsyncWrapper, {
props: {
promise,
},
})

await nextTick()

expect(wrapper.text()).toContain('fallback')

resolve()

await flushPromises()
await nextTick()
await nextTick()

const text = wrapper.text()
expect(text).toContain('resolved')
})
6 changes: 6 additions & 0 deletions test/vue/tsconfig.json
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "esnext"
}
}

0 comments on commit 40b77bb

Please sign in to comment.