Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dynamicImportSettled utility function (#1359)
- Loading branch information
1 parent
861b438
commit 1793937
Showing
6 changed files
with
72 additions
and
2 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
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,20 @@ | ||
<script setup lang="ts"> | ||
import { defineAsyncComponent, ref } from 'vue' | ||
const Hello = defineAsyncComponent({ | ||
loader: () => import('./Hello.vue'), | ||
delay: 0, | ||
}) | ||
const showHello = ref(false) | ||
</script> | ||
|
||
<template> | ||
<button @click="showHello = true"> | ||
Show Hello | ||
</button> | ||
<div v-if="showHello"> | ||
<div>Async component</div> | ||
<Hello :count="1" /> | ||
</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,15 @@ | ||
import { flushPromises, mount } from '@vue/test-utils' | ||
import AsAsync from '../components/AsAsync.vue' | ||
|
||
test('mount component', async () => { | ||
expect(AsAsync).toBeTruthy() | ||
|
||
const wrapper = mount(AsAsync) | ||
|
||
await wrapper.find('button').trigger('click') | ||
|
||
await flushPromises() // start loading, so vitest started loading | ||
await vi.dynamicImportSettled() | ||
|
||
expect(wrapper.html()).toContain('1 x 2 = 2') | ||
}) |
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
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
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