vitest/examples/vue/test/async.test.ts
2022-05-29 23:13:48 +08:00

30 lines
616 B
TypeScript

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
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')
})