|
| 1 | +import Vue, { VNodeData, Component, ComponentOptions, FunctionalComponentOptions } from 'vue' |
| 2 | + |
| 3 | +/** |
| 4 | + * Utility type to declare an extended Vue constructor |
| 5 | + */ |
| 6 | +type VueClass<V extends Vue> = (new (...args: any[]) => V) & typeof Vue |
| 7 | + |
| 8 | +/** |
| 9 | + * Utility type for a selector |
| 10 | + */ |
| 11 | +type Selector = string | Component |
| 12 | + |
| 13 | +/** |
| 14 | + * Utility type for slots |
| 15 | + */ |
| 16 | +type Slots = { |
| 17 | + [key: string]: (Component | string)[] | Component | string |
| 18 | +} |
| 19 | + |
| 20 | +/** |
| 21 | + * Utility type for stubs which can be a string of template as a shorthand |
| 22 | + * If it is an array of string, the specified children are replaced by blank components |
| 23 | + */ |
| 24 | +type Stubs = { |
| 25 | + [key: string]: Component | string | true |
| 26 | +} | string[] |
| 27 | + |
| 28 | +/** |
| 29 | + * Base class of Wrapper and WrapperArray |
| 30 | + * It has common methods on both Wrapper and WrapperArray |
| 31 | + */ |
| 32 | +interface BaseWrapper { |
| 33 | + contains (selector: Selector): boolean |
| 34 | + exists (): boolean |
| 35 | + |
| 36 | + hasAttribute (attribute: string, value: string): boolean |
| 37 | + hasClass (className: string): boolean |
| 38 | + hasProp (prop: string, value: any): boolean |
| 39 | + hasStyle (style: string, value: string): boolean |
| 40 | + |
| 41 | + is (selector: Selector): boolean |
| 42 | + isEmpty (): boolean |
| 43 | + isVueInstance (): boolean |
| 44 | + |
| 45 | + update (): void |
| 46 | + setData (data: object): void |
| 47 | + setProps (props: object): void |
| 48 | + trigger (eventName: string, options?: object): void |
| 49 | +} |
| 50 | + |
| 51 | +interface Wrapper<V extends Vue> extends BaseWrapper { |
| 52 | + readonly vm: V |
| 53 | + readonly element: HTMLElement |
| 54 | + readonly options: WrapperOptions |
| 55 | + |
| 56 | + find<R extends Vue, Ctor extends VueClass<R> = VueClass<R>> (selector: Ctor): Wrapper<R> |
| 57 | + find<R extends Vue> (selector: ComponentOptions<R>): Wrapper<R> |
| 58 | + find (selector: FunctionalComponentOptions): Wrapper<Vue> |
| 59 | + find (selector: string): Wrapper<Vue> |
| 60 | + |
| 61 | + findAll<R extends Vue, Ctor extends VueClass<R> = VueClass<R>> (selector: Ctor): WrapperArray<R> |
| 62 | + findAll<R extends Vue> (selector: ComponentOptions<R>): WrapperArray<R> |
| 63 | + findAll (selector: FunctionalComponentOptions): WrapperArray<Vue> |
| 64 | + findAll (selector: string): WrapperArray<Vue> |
| 65 | + |
| 66 | + html (): string |
| 67 | + text (): string |
| 68 | + name (): string |
| 69 | +} |
| 70 | + |
| 71 | +interface WrapperArray<V extends Vue> extends BaseWrapper { |
| 72 | + readonly length: number |
| 73 | + |
| 74 | + at (index: number): Wrapper<V> |
| 75 | +} |
| 76 | + |
| 77 | +interface WrapperOptions { |
| 78 | + attachedToDocument: boolean |
| 79 | +} |
| 80 | + |
| 81 | +interface MountOptions<V extends Vue> extends ComponentOptions<V> { |
| 82 | + attachToDocument?: boolean |
| 83 | + clone?: boolean |
| 84 | + context?: VNodeData |
| 85 | + localVue?: typeof Vue |
| 86 | + intercept?: object |
| 87 | + slots?: Slots |
| 88 | + stubs?: Stubs |
| 89 | +} |
| 90 | + |
| 91 | +type ShallowOptions<V extends Vue> = MountOptions<V> |
| 92 | + |
| 93 | +export declare function createLocalVue (): typeof Vue |
| 94 | + |
| 95 | +export declare function mount<V extends Vue, Ctor extends VueClass<V> = VueClass<V>> (component: Ctor, options?: MountOptions<V>): Wrapper<V> |
| 96 | +export declare function mount<V extends Vue> (component: ComponentOptions<V>, options?: MountOptions<V>): Wrapper<V> |
| 97 | +export declare function mount (component: FunctionalComponentOptions, options?: MountOptions<Vue>): Wrapper<Vue> |
| 98 | + |
| 99 | +export declare function shallow<V extends Vue, Ctor extends VueClass<V> = VueClass<V>> (component: Ctor, options?: ShallowOptions<V>): Wrapper<V> |
| 100 | +export declare function shallow<V extends Vue> (component: ComponentOptions<V>, options?: ShallowOptions<V>): Wrapper<V> |
| 101 | +export declare function shallow (component: FunctionalComponentOptions, options?: ShallowOptions<Vue>): Wrapper<Vue> |
0 commit comments