import {
- createAsyncComponent,
+ defineAsyncComponent,
h,
Component,
ref,
const timeout = (n: number = 0) => new Promise(r => setTimeout(r, n))
-describe('api: createAsyncComponent', () => {
+describe('api: defineAsyncComponent', () => {
test('simple usage', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent(
+ const Foo = defineAsyncComponent(
() =>
new Promise(r => {
resolve = r as any
test('with loading component', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise(r => {
resolve = r as any
test('with loading component + explicit delay (0)', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise(r => {
resolve = r as any
test('error without error component', async () => {
let resolve: (comp: Component) => void
let reject: (e: Error) => void
- const Foo = createAsyncComponent(
+ const Foo = defineAsyncComponent(
() =>
new Promise((_resolve, _reject) => {
resolve = _resolve as any
test('error with error component', async () => {
let resolve: (comp: Component) => void
let reject: (e: Error) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise((_resolve, _reject) => {
resolve = _resolve as any
test('error with error + loading components', async () => {
let resolve: (comp: Component) => void
let reject: (e: Error) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise((_resolve, _reject) => {
resolve = _resolve as any
test('timeout without error component', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise(_resolve => {
resolve = _resolve as any
test('timeout with error component', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise(_resolve => {
resolve = _resolve as any
test('timeout with error + loading components', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise(_resolve => {
resolve = _resolve as any
test('timeout without error component, but with loading component', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise(_resolve => {
resolve = _resolve as any
test('with suspense', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent(
+ const Foo = defineAsyncComponent(
() =>
new Promise(_resolve => {
resolve = _resolve as any
test('suspensible: false', async () => {
let resolve: (comp: Component) => void
- const Foo = createAsyncComponent({
+ const Foo = defineAsyncComponent({
loader: () =>
new Promise(_resolve => {
resolve = _resolve as any
test('suspense with error handling', async () => {
let reject: (e: Error) => void
- const Foo = createAsyncComponent(
+ const Foo = defineAsyncComponent(
() =>
new Promise((_resolve, _reject) => {
reject = _reject
})
// a simple async factory for testing purposes only.
- function createAsyncComponent<T extends ComponentOptions>(
+ function defineAsyncComponent<T extends ComponentOptions>(
comp: T,
delay: number = 0
) {
}
test('fallback content', async () => {
- const Async = createAsyncComponent({
+ const Async = defineAsyncComponent({
render() {
return h('div', 'async')
}
test('nested async deps', async () => {
const calls: string[] = []
- const AsyncOuter = createAsyncComponent({
+ const AsyncOuter = defineAsyncComponent({
setup() {
onMounted(() => {
calls.push('outer mounted')
}
})
- const AsyncInner = createAsyncComponent(
+ const AsyncInner = defineAsyncComponent(
{
setup() {
onMounted(() => {
})
test('onResolve', async () => {
- const Async = createAsyncComponent({
+ const Async = defineAsyncComponent({
render() {
return h('div', 'async')
}
})
test('content update before suspense resolve', async () => {
- const Async = createAsyncComponent({
+ const Async = defineAsyncComponent({
setup(props: { msg: string }) {
return () => h('div', props.msg)
}
const toggle = ref(true)
const unmounted = jest.fn()
- const Async = createAsyncComponent({
+ const Async = defineAsyncComponent({
setup() {
onUnmounted(unmounted)
return () => h('div', 'async')
const mounted = jest.fn()
const unmounted = jest.fn()
- const Async = createAsyncComponent({
+ const Async = defineAsyncComponent({
setup() {
onMounted(mounted)
onUnmounted(unmounted)
test('nested suspense (parent resolves first)', async () => {
const calls: string[] = []
- const AsyncOuter = createAsyncComponent(
+ const AsyncOuter = defineAsyncComponent(
{
setup: () => {
onMounted(() => {
1
)
- const AsyncInner = createAsyncComponent(
+ const AsyncInner = defineAsyncComponent(
{
setup: () => {
onMounted(() => {
test('nested suspense (child resolves first)', async () => {
const calls: string[] = []
- const AsyncOuter = createAsyncComponent(
+ const AsyncOuter = defineAsyncComponent(
{
setup: () => {
onMounted(() => {
10
)
- const AsyncInner = createAsyncComponent(
+ const AsyncInner = defineAsyncComponent(
{
setup: () => {
onMounted(() => {
const msg = ref('nested msg')
const calls: number[] = []
- const AsyncChildWithSuspense = createAsyncComponent({
+ const AsyncChildWithSuspense = defineAsyncComponent({
setup(props: { msg: string }) {
onMounted(() => {
calls.push(0)
}
})
- const AsyncInsideNestedSuspense = createAsyncComponent(
+ const AsyncInsideNestedSuspense = defineAsyncComponent(
{
setup(props: { msg: string }) {
onMounted(() => {
20
)
- const AsyncChildParent = createAsyncComponent({
+ const AsyncChildParent = defineAsyncComponent({
setup(props: { msg: string }) {
onMounted(() => {
calls.push(1)
}
})
- const NestedAsyncChild = createAsyncComponent(
+ const NestedAsyncChild = defineAsyncComponent(
{
setup(props: { msg: string }) {
onMounted(() => {
test('new async dep after resolve should cause suspense to restart', async () => {
const toggle = ref(false)
- const ChildA = createAsyncComponent({
+ const ChildA = defineAsyncComponent({
setup() {
return () => h('div', 'Child A')
}
})
- const ChildB = createAsyncComponent({
+ const ChildB = defineAsyncComponent({
setup() {
return () => h('div', 'Child B')
}