Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add vue suspense test #290

Merged
merged 9 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/vue/components/AsyncComp.vue
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "esnext"
}
}