forked from vuejs/composition-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defineAsyncComponent.test-d.ts
88 lines (77 loc) · 2.06 KB
/
defineAsyncComponent.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { AsyncComponent } from 'vue'
import { defineAsyncComponent, defineComponent, expectType } from './index'
function asyncComponent1() {
return Promise.resolve().then(() => {
return defineComponent({})
})
}
function asyncComponent2() {
return Promise.resolve().then(() => {
return {
template: 'ASYNC',
}
})
}
const syncComponent1 = defineComponent({
template: '',
})
const syncComponent2 = {
template: '',
}
defineAsyncComponent(asyncComponent1)
defineAsyncComponent(asyncComponent2)
defineAsyncComponent({
loader: asyncComponent1,
delay: 200,
timeout: 3000,
errorComponent: syncComponent1,
loadingComponent: syncComponent1,
})
defineAsyncComponent({
loader: asyncComponent2,
delay: 200,
timeout: 3000,
errorComponent: syncComponent2,
loadingComponent: syncComponent2,
})
defineAsyncComponent(
() =>
new Promise((resolve, reject) => {
resolve(syncComponent1)
})
)
defineAsyncComponent(
() =>
new Promise((resolve, reject) => {
resolve(syncComponent2)
})
)
const component = defineAsyncComponent({
// The factory function
loader: asyncComponent1,
// A component to use while the async component is loading
loadingComponent: defineComponent({}),
// A component to use if the load fails
errorComponent: defineComponent({}),
// Delay before showing the loading component. Default: 200ms.
delay: 200,
// The error component will be displayed if a timeout is
// provided and exceeded. Default: Infinity.
timeout: 3000,
// Defining if component is suspensible. Default: true.
suspensible: false,
/**
*
* @param {*} error Error message object
* @param {*} retry A function that indicating whether the async component should retry when the loader promise rejects
* @param {*} fail End of failure
* @param {*} attempts Maximum allowed retries number
*/
onError(error, retry, fail, attempts) {
expectType<() => void>(retry)
expectType<() => void>(fail)
expectType<number>(attempts)
expectType<Error>(error)
},
})
expectType<AsyncComponent>(component)