Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ jobs:
- run: yarn build
env:
CI: true
- run: yarn tsd
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"module": "dist/vue-test-utils.esm-bundler.js",
"files": [
"dist",
"README.md"
"README.md",
"dist/index.d.ts"
],
"dependencies": {
"lodash": "^4.17.15"
Expand All @@ -21,6 +22,7 @@
"@rollup/plugin-node-resolve": "^7.1.3",
"@types/estree": "^0.0.42",
"@types/jest": "^24.9.1",
"@types/node": "12.12.35",
"@types/lodash": "^4.14.149",
"@vue/compiler-sfc": "^3.0.0-alpha.13",
"babel-jest": "^25.2.3",
Expand All @@ -33,6 +35,7 @@
"rollup": "^1.31.1",
"rollup-plugin-typescript2": "^0.26.0",
"ts-jest": "^25.0.0",
"tsd": "0.11.0",
"typescript": "^3.7.5",
"vue": "^3.0.0-alpha.13",
"vue-jest": "vuejs/vue-jest#next",
Expand All @@ -48,6 +51,7 @@
},
"scripts": {
"test": "yarn jest --runInBand tests",
"tsd": "tsd",
"build": "yarn rollup -c rollup.config.js",
"lint": "prettier -c --parser typescript \"(src|tests)/**/*.ts?(x)\"",
"lint:fix": "yarn lint --write"
Expand All @@ -61,5 +65,12 @@
"*.ts": [
"prettier --parser=typescript --write"
]
},
"tsd": {
"directory": "test-dts",
"compilerOptions": {
"strict": false,
"lib": ["esnext", "dom"]
}
}
}
16 changes: 10 additions & 6 deletions src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ interface MountingOptions {
stubs?: Record<string, any>
}

export function mount<T extends any>(
originalComponent: any,
export function mount<TestedComponent extends ComponentPublicInstance>(
originalComponent: new () => TestedComponent,
options?: MountingOptions
): VueWrapper<TestedComponent>
export function mount(
originalComponent: Component,
options?: MountingOptions
): VueWrapper<any>
export function mount<T extends ComponentPublicInstance>(
originalComponent: new () => T,
export function mount(
originalComponent: any,
options?: MountingOptions
): VueWrapper<T> {
): VueWrapper<any> {
const component = { ...originalComponent }

// Reset the document.body
Expand Down Expand Up @@ -158,5 +162,5 @@ export function mount<T extends ComponentPublicInstance>(
// mount the app!
const app = vm.mount(el)

return createWrapper<T>(app, events, setProps)
return createWrapper(app, events, setProps)
}
23 changes: 23 additions & 0 deletions test-dts/index.d-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expectType } from 'tsd'
import { defineComponent } from 'vue'
import { mount } from '../src'

const App = defineComponent({
props: {
a: String
},
template: ''
})

let wrapper = mount(App)
expectType<string>(wrapper.vm.a)

const AppWithoutDefine = {
props: {
a: String
},
template: ''
}

wrapper = mount(AppWithoutDefine)
expectType<string>(wrapper.vm.a)
Loading