|
1 | 1 | // Minimum TypeScript Version: 4.0
|
2 | 2 | /* eslint-disable @typescript-eslint/no-explicit-any */
|
3 | 3 |
|
| 4 | +import {VNodeChild} from 'vue' |
4 | 5 | import {MountingOptions} from '@vue/test-utils'
|
5 | 6 | import {queries, EventType, BoundFunctions} from '@testing-library/dom'
|
6 | 7 | // eslint-disable-next-line import/no-extraneous-dependencies
|
7 | 8 | import {OptionsReceived as PrettyFormatOptions} from 'pretty-format'
|
| 9 | +import {ComponentProps, ComponentSlots} from 'vue-component-type-helpers' |
| 10 | +import {RemoveIndexSignature} from 'type-fest' |
8 | 11 |
|
9 | 12 | // NOTE: fireEvent is overridden below
|
10 | 13 | export * from '@testing-library/dom'
|
@@ -44,12 +47,26 @@ interface VueTestingLibraryRenderOptions {
|
44 | 47 | container?: Element
|
45 | 48 | baseElement?: Element
|
46 | 49 | }
|
47 |
| -export type RenderOptions = VueTestingLibraryRenderOptions & |
48 |
| - VueTestUtilsRenderOptions |
49 | 50 |
|
50 |
| -export function render( |
51 |
| - TestComponent: any, // this makes me sad :sob: |
52 |
| - options?: RenderOptions, |
| 51 | +type AllowNonFunctionSlots<Slots> = { |
| 52 | + [K in keyof Slots]: Slots[K] | VNodeChild |
| 53 | +} |
| 54 | +type ExtractSlots<C> = AllowNonFunctionSlots< |
| 55 | + Partial<RemoveIndexSignature<ComponentSlots<C>>> |
| 56 | +> |
| 57 | + |
| 58 | +export interface RenderOptions<C> |
| 59 | + extends Omit< |
| 60 | + VueTestingLibraryRenderOptions & VueTestUtilsRenderOptions, |
| 61 | + 'props' | 'slots' |
| 62 | + > { |
| 63 | + props?: ComponentProps<C> |
| 64 | + slots?: ExtractSlots<C> |
| 65 | +} |
| 66 | + |
| 67 | +export function render<C>( |
| 68 | + TestComponent: C, |
| 69 | + options?: RenderOptions<C>, |
53 | 70 | ): RenderResult
|
54 | 71 |
|
55 | 72 | export type AsyncFireObject = {
|
|
0 commit comments