Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit ce7b824

Browse files
committed
Add typings
Followed recommendations in [dtslint tool](https://github.com/microsoft/dtslint) and [TypeScript documentation](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html). Took tsconfig.json and tslint.json from @testing-library/dom, although it looks like they just copied the examples in the dtslint docs. Closes testing-library#60.
1 parent b98df9b commit ce7b824

File tree

6 files changed

+353
-0
lines changed

6 files changed

+353
-0
lines changed

package-lock.json

Lines changed: 145 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"version": "1.2.0",
44
"description": "Simple and complete Vue DOM testing utilities that encourage good testing practices.",
55
"main": "dist/vue-testing-library.js",
6+
"types": "types",
67
"scripts": {
78
"lint": "eslint --ext .js,.vue .",
89
"lint:fix": "npm run lint -- --fix",
10+
"dtslint": "dtslint types",
911
"test": "jest --coverage",
1012
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
1113
"prepublishOnly": "babel src --out-dir dist"
1214
},
1315
"files": [
1416
"dist",
17+
"types/index.d.ts",
1518
"cleanup-after-each.js"
1619
],
1720
"repository": {
@@ -46,6 +49,7 @@
4649
"babel-eslint": "^10.0.2",
4750
"babel-jest": "^24.8.0",
4851
"coveralls": "^3.0.5",
52+
"dtslint": "^0.9.1",
4953
"eslint": "^6.1.0",
5054
"eslint-config-prettier": "^6.0.0",
5155
"eslint-config-standard": "^13.0.1",

types/index.d.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// TypeScript Version: 3.0
2+
import { ThisTypedMountOptions, VueClass } from '@vue/test-utils'
3+
import Vue from 'vue'
4+
import { Store, StoreOptions } from 'vuex'
5+
import Router, { RouterOptions, RouteConfig } from 'vue-router'
6+
import { getQueriesForElement, BoundFunctions, queries, EventType, FireFunction } from '@testing-library/dom'
7+
8+
// NOTE: fireEvent is overridden below
9+
export * from '@testing-library/dom'
10+
11+
export function cleanup(): void
12+
13+
export interface RenderOptions<V extends Vue, S = {}> extends
14+
// The props and store options special-cased by vue-testing-library and NOT passed to mount().
15+
// In TS 3.5+: Omit<ThisTypedMountOptions<V>, "store" | "props">
16+
Pick<ThisTypedMountOptions<V>, Exclude<keyof ThisTypedMountOptions<V>, "store" | "props">> {
17+
props?: object
18+
store?: StoreOptions<S>
19+
routes?: RouteConfig[]
20+
}
21+
22+
export type ConfigurationCallback<V extends Vue> =
23+
(vue: V, store: Store<any>, router: Router) => Partial<ThisTypedMountOptions<V>> | void
24+
25+
export type ComponentHarness = BoundFunctions<typeof queries> & {
26+
container: HTMLElement
27+
baseElement: HTMLBodyElement
28+
debug(el?: HTMLElement): void
29+
unmount(): void
30+
isUnmounted(): boolean
31+
html(): string
32+
emitted(): { [name: string]: any[][] }
33+
updateProps(props: object): Promise<void>
34+
}
35+
36+
export function render<V extends Vue>(
37+
TestComponent: VueClass<V>,
38+
options?: RenderOptions<V>,
39+
configure?: ConfigurationCallback<V>
40+
): ComponentHarness
41+
42+
export type AsyncFireObject = {
43+
[K in EventType]: (element: Document | Element | Window, options?: {}) => Promise<void>
44+
}
45+
46+
export interface VueFireObject extends AsyncFireObject {
47+
touch(element: Document | Element | Window): Promise<void>
48+
update(element: HTMLOptionElement): Promise<void>
49+
update(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, value?: string): Promise<void>
50+
}
51+
52+
export const fireEvent: FireFunction & VueFireObject

0 commit comments

Comments
 (0)