File tree Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ import { attachEmitListener } from './emitMixin'
38
38
import { createDataMixin } from './dataMixin'
39
39
import { MOUNT_COMPONENT_REF , MOUNT_PARENT_NAME } from './constants'
40
40
import { stubComponents } from './stubs'
41
- import { VueConstructor } from 'vue-class-component'
42
41
43
42
// NOTE this should come from `vue`
44
43
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps
@@ -74,10 +73,10 @@ export type ObjectEmitsOptions = Record<
74
73
export type EmitsOptions = ObjectEmitsOptions | string [ ]
75
74
76
75
// Class component
77
- export function mount (
78
- originalComponent : VueConstructor ,
76
+ export function mount < V > (
77
+ originalComponent : new ( ... args : any [ ] ) => V ,
79
78
options ?: MountingOptions < any >
80
- ) : VueWrapper < ComponentPublicInstance < any > >
79
+ ) : VueWrapper < ComponentPublicInstance < V > >
81
80
82
81
// Functional component with emits
83
82
export function mount < Props , E extends EmitsOptions = { } > (
Original file line number Diff line number Diff line change 5
5
FunctionalComponent ,
6
6
reactive
7
7
} from 'vue'
8
+ import { Options , Vue } from 'vue-class-component'
8
9
import { mount } from '../src'
9
10
10
11
const AppWithDefine = defineComponent ( {
@@ -203,3 +204,25 @@ mount(FunctionalComponentEmit)
203
204
204
205
// @ts -ignore vue 3.0.2 doesn't work. FIX: https://github.com/vuejs/vue-next/pull/2494
205
206
mount ( defineComponent ( FunctionalComponentEmit ) )
207
+
208
+ // class component
209
+
210
+ @Options ( {
211
+ props : {
212
+ msg : String
213
+ }
214
+ } )
215
+ class ClassComponent extends Vue {
216
+ dataText : string = ''
217
+ get computedMsg ( ) : string {
218
+ return `Message: ${ ( this . $props as any ) . msg } `
219
+ }
220
+
221
+ changeMessage ( text : string ) : void {
222
+ this . dataText = 'Updated'
223
+ }
224
+ }
225
+
226
+ // @ts -expect-error it requires an argument
227
+ expectError ( mount ( ClassComponent , { } ) . vm . changeMessage ( ) )
228
+ mount ( ClassComponent , { } ) . vm . changeMessage ( '' )
Original file line number Diff line number Diff line change 1
1
import { expectError , expectType } from 'tsd'
2
2
import { defineComponent } from 'vue'
3
+ import { Options , Vue } from 'vue-class-component'
3
4
import { shallowMount } from '../src'
4
5
5
6
const AppWithDefine = defineComponent ( {
@@ -99,3 +100,24 @@ expectError(
99
100
shallowMount ( AppWithoutProps , {
100
101
props : { b : 'Hello' } as never
101
102
} )
103
+
104
+ // class component
105
+ @Options ( {
106
+ props : {
107
+ msg : String
108
+ }
109
+ } )
110
+ class ClassComponent extends Vue {
111
+ dataText : string = ''
112
+ get computedMsg ( ) : string {
113
+ return `Message: ${ ( this . $props as any ) . msg } `
114
+ }
115
+
116
+ changeMessage ( text : string ) : void {
117
+ this . dataText = 'Updated'
118
+ }
119
+ }
120
+
121
+ // @ts -expect-error it requires an argument
122
+ expectError ( mount ( ClassComponent , { } ) . vm . changeMessage ( ) )
123
+ shallowMount ( ClassComponent , { } ) . vm . changeMessage ( '' )
You can’t perform that action at this time.
0 commit comments