forked from vitest-dev/vitest
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add vue suspense test (vitest-dev#290)
- Loading branch information
1 parent
0c14b1a
commit 40b77bb
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"target": "esnext" | ||
} | ||
} |