diff --git a/src/baseWrapper.ts b/src/baseWrapper.ts index b869ee91b..0a1f0e462 100644 --- a/src/baseWrapper.ts +++ b/src/baseWrapper.ts @@ -1,10 +1,13 @@ import { textContent } from './utils' import type { TriggerOptions } from './createDomEvent' import { - Component, ComponentInternalInstance, + ComponentOptions, ComponentPublicInstance, + ComputedOptions, + CreateComponentPublicInstance, FunctionalComponent, + MethodOptions, nextTick } from 'vue' import { createDOMEvent } from './createDomEvent' @@ -100,6 +103,29 @@ export default abstract class BaseWrapper // searching by string without specifying component results in WrapperLike object findComponent(selector: string): WrapperLike + // Find Component Options aka plain object + findComponent< + Props, + RawBindings = any, + D = any, + C extends ComputedOptions = ComputedOptions, + M extends MethodOptions = MethodOptions + >( + selector: ComponentOptions + ): VueWrapper> + findComponent( + selector: string + ): VueWrapper< + T extends ComponentOptions< + infer Props, + infer RawBindings, + infer D, + infer C, + infer M + > + ? CreateComponentPublicInstance + : VueWrapper + > // searching for component created via defineComponent results in VueWrapper of proper type findComponent( selector: T | Exclude @@ -116,9 +142,6 @@ export default abstract class BaseWrapper findComponent( selector: T | FindComponentSelector ): VueWrapper - // Find my CatchAll component - findComponent(selector: T): DOMWrapper - findComponent(selector: string): DOMWrapper // catch all declaration findComponent(selector: FindComponentSelector): WrapperLike diff --git a/src/types.ts b/src/types.ts index ee15cd0f4..4bda84b1c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,6 +21,7 @@ export interface NameSelector { export type FindAllComponentsSelector = | DefinedComponent | FunctionalComponent + | ComponentOptions | NameSelector | string export type FindComponentSelector = RefSelector | FindAllComponentsSelector