Skip to content

Add typings #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
145 changes: 145 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -3,15 +3,18 @@
"version": "1.2.0",
"description": "Simple and complete Vue DOM testing utilities that encourage good testing practices.",
"main": "dist/vue-testing-library.js",
"types": "types",
"scripts": {
"lint": "eslint --ext .js,.vue .",
"lint:fix": "npm run lint -- --fix",
"dtslint": "dtslint types",
"test": "jest --coverage",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"prepublishOnly": "babel src --out-dir dist"
},
"files": [
"dist",
"types/index.d.ts",
"cleanup-after-each.js"
],
"repository": {
@@ -46,6 +49,7 @@
"babel-eslint": "^10.0.2",
"babel-jest": "^24.8.0",
"coveralls": "^3.0.5",
"dtslint": "^0.9.1",
"eslint": "^6.1.0",
"eslint-config-prettier": "^6.0.0",
"eslint-config-standard": "^13.0.1",
52 changes: 52 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// TypeScript Version: 3.0
import { ThisTypedMountOptions, VueClass } from '@vue/test-utils'
import Vue from 'vue'
import { Store, StoreOptions } from 'vuex'
import Router, { RouterOptions, RouteConfig } from 'vue-router'
import { getQueriesForElement, BoundFunctions, queries, EventType, FireFunction } from '@testing-library/dom'

// NOTE: fireEvent is overridden below
export * from '@testing-library/dom'

export function cleanup(): void

export interface RenderOptions<V extends Vue, S = {}> extends
// The props and store options special-cased by vue-testing-library and NOT passed to mount().
// In TS 3.5+: Omit<ThisTypedMountOptions<V>, "store" | "props">
Pick<ThisTypedMountOptions<V>, Exclude<keyof ThisTypedMountOptions<V>, "store" | "props">> {
props?: object
store?: StoreOptions<S>
routes?: RouteConfig[]
}

export type ConfigurationCallback<V extends Vue> =
(vue: V, store: Store<any>, router: Router) => Partial<ThisTypedMountOptions<V>> | void

export type ComponentHarness = BoundFunctions<typeof queries> & {
container: HTMLElement
baseElement: HTMLBodyElement
debug(el?: HTMLElement): void
unmount(): void
isUnmounted(): boolean
html(): string
emitted(): { [name: string]: any[][] }
updateProps(props: object): Promise<void>
}

export function render<V extends Vue>(
TestComponent: VueClass<V>,
options?: RenderOptions<V>,
configure?: ConfigurationCallback<V>
): ComponentHarness

export type AsyncFireObject = {
[K in EventType]: (element: Document | Element | Window, options?: {}) => Promise<void>
}

export interface VueFireObject extends AsyncFireObject {
touch(element: Document | Element | Window): Promise<void>
update(element: HTMLOptionElement): Promise<void>
update(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, value?: string): Promise<void>
}

export const fireEvent: FireFunction & VueFireObject
Loading