diff --git a/src/mount.ts b/src/mount.ts index 4c51a5d17..e8de5395c 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -27,7 +27,6 @@ import { import { config } from './config' import { GlobalMountOptions } from './types' import { - isClassComponent, isFunctionalComponent, isObjectComponent, mergeGlobalProperties @@ -38,7 +37,6 @@ import { attachEmitListener } from './emitMixin' import { createDataMixin } from './dataMixin' import { MOUNT_COMPONENT_REF, MOUNT_PARENT_NAME } from './constants' import { stubComponents } from './stubs' -import { VueConstructor } from 'vue-class-component' // NOTE this should come from `vue` type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps @@ -73,11 +71,24 @@ export type ObjectEmitsOptions = Record< > export type EmitsOptions = ObjectEmitsOptions | string[] -// Class component -export function mount( - originalComponent: VueConstructor, +// Class component - no props +export function mount( + originalComponent: { + new (...args: any[]): V + registerHooks(keys: string[]): void + }, options?: MountingOptions -): VueWrapper> +): VueWrapper> + +// Class component - props +export function mount( + originalComponent: { + new (...args: any[]): V + props(Props: P): any + registerHooks(keys: string[]): void + }, + options?: MountingOptions

+): VueWrapper> // Functional component with emits export function mount( diff --git a/test-dts/mount.d-test.ts b/test-dts/mount.d-test.ts index cb02e60b7..f00a792bb 100644 --- a/test-dts/mount.d-test.ts +++ b/test-dts/mount.d-test.ts @@ -5,6 +5,7 @@ import { FunctionalComponent, reactive } from 'vue' +import { Options, Vue } from 'vue-class-component' import { mount } from '../src' const AppWithDefine = defineComponent({ @@ -203,3 +204,25 @@ mount(FunctionalComponentEmit) // @ts-ignore vue 3.0.2 doesn't work. FIX: https://github.com/vuejs/vue-next/pull/2494 mount(defineComponent(FunctionalComponentEmit)) + +// class component + +@Options({ + props: { + msg: String + } +}) +class ClassComponent extends Vue { + dataText: string = '' + get computedMsg(): string { + return `Message: ${(this.$props as any).msg}` + } + + changeMessage(text: string): void { + this.dataText = 'Updated' + } +} + +// @ts-expect-error it requires an argument +expectError(mount(ClassComponent, {}).vm.changeMessage()) +mount(ClassComponent, {}).vm.changeMessage('') diff --git a/test-dts/shallowMount.d-test.ts b/test-dts/shallowMount.d-test.ts index 8887623ea..9cfdd0f96 100644 --- a/test-dts/shallowMount.d-test.ts +++ b/test-dts/shallowMount.d-test.ts @@ -1,5 +1,6 @@ import { expectError, expectType } from 'tsd' import { defineComponent } from 'vue' +import { Options, Vue } from 'vue-class-component' import { shallowMount } from '../src' const AppWithDefine = defineComponent({ @@ -99,3 +100,24 @@ expectError( shallowMount(AppWithoutProps, { props: { b: 'Hello' } as never }) + +// class component +@Options({ + props: { + msg: String + } +}) +class ClassComponent extends Vue { + dataText: string = '' + get computedMsg(): string { + return `Message: ${(this.$props as any).msg}` + } + + changeMessage(text: string): void { + this.dataText = 'Updated' + } +} + +// @ts-expect-error it requires an argument +expectError(shallowMount(ClassComponent, {}).vm.changeMessage()) +shallowMount(ClassComponent, {}).vm.changeMessage('')