Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dbcf740

Browse files
authored
feat: Move types from DefinitelyTyped into this repo (#165)
* Add required dependencies * Add types * Update readme * Bump deps and fix build and eslint to fix node 15
1 parent 53ff893 commit dbcf740

File tree

7 files changed

+255
-11
lines changed

7 files changed

+255
-11
lines changed

‎.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = {
2+
parserOptions: {
3+
parser: '@typescript-eslint/parser',
4+
},
25
extends: [
36
'./node_modules/kcd-scripts/eslint.js',
47
'plugin:vue/recommended',

‎README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
4141
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
4242

43+
4344
- [Installation](#installation)
4445
- [A basic example](#a-basic-example)
4546
- [More examples](#more-examples)
@@ -173,8 +174,7 @@ light-weight, simple, and understandable.
173174

174175
## Typings
175176

176-
The TypeScript type definitions are in the [DefinitelyTyped repo][types] and
177-
bundled with Vue Testing Library.
177+
The TypeScript type definitions are in the [types][types-directory] directory.
178178

179179
## ESLint support
180180

@@ -248,7 +248,6 @@ instead of filing an issue on GitHub.
248248
[license]: https://github.com/testing-library/vue-testing-library/blob/master/LICENSE
249249
[discord]: https://testing-library.com/discord
250250
[discord-badge]: https://img.shields.io/discord/723559267868737556.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2&style=flat-square
251-
[types]: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__vue
252251
[jest-dom]: https://github.com/testing-library/jest-dom
253252
[which-query]: https://testing-library.com/docs/guide-which-query
254253
[guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106
@@ -262,6 +261,7 @@ instead of filing an issue on GitHub.
262261
[add-issue-bug]: https://github.com/testing-library/vue-testing-library/issues/new?assignees=&labels=bug&template=bug_report.md&title=
263262
[add-issue]: (https://github.com/testing-library/vue-testing-library/issues/new)
264263

264+
[types-directory]: https://github.com/testing-library/vue-testing-library/blob/master/types
265265
[test-directory]: https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__
266266
[vuex-example]: https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/vuex.js
267267
[vue-router-example]: https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/vue-router.js

‎package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
"version": "0.0.0-semantically-released",
44
"description": "Simple and complete Vue DOM testing utilities that encourage good testing practices.",
55
"main": "dist/vue-testing-library.js",
6+
"types": "types/index.d.ts",
67
"scripts": {
78
"format": "kcd-scripts format",
89
"build": "kcd-scripts build",
910
"lint": "kcd-scripts lint",
1011
"test": "kcd-scripts test",
1112
"test:update": "npm test -- --updateSnapshot --coverage",
1213
"validate": "kcd-scripts validate",
14+
"typecheck": "dtslint ./types/",
1315
"setup": "npm install && npm run validate -s"
1416
},
1517
"engines": {
1618
"node": ">10.18"
1719
},
1820
"files": [
21+
"types",
1922
"dist",
2023
"cleanup-after-each.js"
2124
],
@@ -40,34 +43,37 @@
4043
"author": "Daniel Cook",
4144
"license": "MIT",
4245
"dependencies": {
43-
"@babel/runtime": "^7.11.2",
44-
"@testing-library/dom": "^7.24.3",
45-
"@types/testing-library__vue": "^5.0.0",
46+
"@babel/runtime": "^7.12.5",
47+
"@testing-library/dom": "^7.26.6",
4648
"@vue/test-utils": "^1.1.0"
4749
},
4850
"devDependencies": {
4951
"@babel/plugin-transform-runtime": "^7.11.5",
50-
"@testing-library/jest-dom": "^5.11.4",
52+
"@testing-library/jest-dom": "^5.11.6",
53+
"@types/estree": "0.0.45",
5154
"apollo-boost": "^0.4.9",
5255
"apollo-cache-inmemory": "^1.6.6",
5356
"axios": "^0.20.0",
54-
"eslint-plugin-vue": "^6.2.2",
57+
"dtslint": "^4.0.5",
58+
"eslint": "^7.13.0",
59+
"eslint-plugin-vue": "^7.1.0",
5560
"graphql": "^15.3.0",
5661
"graphql-tag": "^2.11.0",
5762
"isomorphic-unfetch": "^3.0.0",
5863
"jest-serializer-vue": "^2.0.2",
59-
"kcd-scripts": "^6.5.1",
64+
"kcd-scripts": "^7.0.3",
6065
"lodash.merge": "^4.6.2",
6166
"msw": "^0.21.2",
6267
"portal-vue": "^2.1.7",
68+
"typescript": "^4.0.5",
6369
"vee-validate": "^2.2.15",
6470
"vue": "^2.6.12",
6571
"vue-apollo": "^3.0.4",
6672
"vue-i18n": "^8.21.1",
6773
"vue-jest": "^4.0.0-rc.0",
68-
"vue-router": "^3.4.5",
74+
"vue-router": "^3.4.9",
6975
"vue-template-compiler": "^2.6.12",
70-
"vuetify": "^2.3.10",
76+
"vuetify": "^2.3.17",
7177
"vuex": "^3.5.1"
7278
},
7379
"peerDependencies": {

‎types/index.d.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// TypeScript Version: 4.0
2+
3+
import Vue, {ComponentOptions} from 'vue'
4+
import {ThisTypedMountOptions, VueClass} from '@vue/test-utils'
5+
import {Store, StoreOptions} from 'vuex'
6+
import Router, {RouteConfig} from 'vue-router'
7+
// eslint-disable-next-line import/no-extraneous-dependencies
8+
import {OptionsReceived as PrettyFormatOptions} from 'pretty-format'
9+
import {queries, EventType, BoundFunctions} from '@testing-library/dom'
10+
11+
// NOTE: fireEvent is overridden below
12+
export * from '@testing-library/dom'
13+
14+
export interface RenderResult extends BoundFunctions<typeof queries> {
15+
container: HTMLElement
16+
baseElement: HTMLElement
17+
debug: (
18+
baseElement?:
19+
| HTMLElement
20+
| DocumentFragment
21+
| Array<HTMLElement | DocumentFragment>,
22+
maxLength?: number,
23+
options?: PrettyFormatOptions,
24+
) => void
25+
unmount(): void
26+
isUnmounted(): boolean
27+
html(): string
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29+
emitted(): {[name: string]: any[][]}
30+
updateProps(props: object): Promise<void>
31+
}
32+
33+
export interface RenderOptions<V extends Vue, S = {}>
34+
// The props and store options special-cased by Vue Testing Library and NOT passed to mount().
35+
extends Omit<ThisTypedMountOptions<V>, 'store' | 'props'> {
36+
props?: object
37+
store?: StoreOptions<S>
38+
routes?: RouteConfig[]
39+
container?: HTMLElement
40+
baseElement?: HTMLElement
41+
}
42+
43+
export type ConfigurationCallback<V extends Vue> = (
44+
localVue: typeof Vue,
45+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
46+
store: Store<any>,
47+
router: Router,
48+
) => Partial<ThisTypedMountOptions<V>> | void
49+
50+
export function render<V extends Vue>(
51+
TestComponent: VueClass<V> | ComponentOptions<V>,
52+
options?: RenderOptions<V>,
53+
configure?: ConfigurationCallback<V>,
54+
): RenderResult
55+
56+
export type AsyncFireObject = {
57+
[K in EventType]: (
58+
element: Document | Element | Window,
59+
options?: {},
60+
) => Promise<void>
61+
}
62+
63+
export interface VueFireEventObject extends AsyncFireObject {
64+
(element: Document | Element | Window, event: Event): Promise<void>
65+
touch(element: Document | Element | Window): Promise<void>
66+
update(element: HTMLOptionElement): Promise<void>
67+
update(
68+
element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,
69+
value: string,
70+
): Promise<void>
71+
update(element: HTMLElement, value?: string): Promise<void>
72+
}
73+
74+
export const fireEvent: VueFireEventObject

‎types/test.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import Vue from 'vue'
2+
import {render, fireEvent, screen, waitFor} from '@testing-library/vue'
3+
4+
declare const elem: HTMLElement
5+
6+
const SomeComponent = Vue.extend({
7+
name: 'SomeComponent',
8+
props: {
9+
foo: {type: Number, default: 0},
10+
bar: {type: String, default: '0'},
11+
},
12+
})
13+
14+
export async function testRender() {
15+
const page = render({template: '<div />'})
16+
17+
// single queries
18+
page.getByText('foo')
19+
page.queryByText('foo')
20+
await page.findByText('foo')
21+
22+
// multiple queries
23+
page.getAllByText('bar')
24+
page.queryAllByText('bar')
25+
await page.findAllByText('bar')
26+
27+
// helpers
28+
const {container, unmount, debug} = page
29+
30+
debug(container)
31+
32+
debug(elem) // $ExpectType void
33+
debug([elem, elem], 100, {highlight: false}) // $ExpectType void
34+
35+
unmount()
36+
}
37+
38+
export function testRenderOptions() {
39+
const container = document.createElement('div')
40+
const options = {container}
41+
render({template: 'div'}, options)
42+
}
43+
44+
export async function testFireEvent() {
45+
const {container} = render({template: 'button'})
46+
await fireEvent.click(container)
47+
}
48+
49+
export function testDebug() {
50+
const {debug, getAllByTestId} = render({
51+
render(h) {
52+
return h('div', [
53+
h('h1', {attrs: {'data-testId': 'testid'}}, 'hello world'),
54+
h('h2', {attrs: {'data-testId': 'testid'}}, 'hello world'),
55+
])
56+
},
57+
})
58+
59+
debug(getAllByTestId('testid'))
60+
}
61+
62+
export async function testScreen() {
63+
render({template: 'button'})
64+
65+
await screen.findByRole('button')
66+
}
67+
68+
export async function testWaitFor() {
69+
const {container} = render({template: 'button'})
70+
await fireEvent.click(container)
71+
await waitFor(() => {})
72+
}
73+
74+
export function testOptions() {
75+
render(SomeComponent, {
76+
// options for new Vue()
77+
name: 'SomeComponent',
78+
methods: {
79+
glorb() {
80+
return 42
81+
},
82+
},
83+
// options for vue-test-utils mount()
84+
slots: {
85+
quux: '<p>Baz</p>',
86+
},
87+
mocks: {
88+
isThisFake() {
89+
return true
90+
},
91+
},
92+
// options for Vue Testing Library render()
93+
container: elem,
94+
baseElement: elem,
95+
props: {
96+
foo: 9,
97+
bar: 'x',
98+
},
99+
store: {
100+
state: {
101+
foos: [4, 5],
102+
bars: ['a', 'b'],
103+
},
104+
getters: {
105+
fooCount() {
106+
return this.foos.length
107+
},
108+
},
109+
},
110+
routes: [
111+
{path: '/', name: 'home', component: SomeComponent},
112+
{
113+
path: '/about',
114+
name: 'about',
115+
component: () => Promise.resolve(SomeComponent),
116+
},
117+
],
118+
})
119+
}
120+
121+
export function testConfigCallback() {
122+
const ExamplePlugin: Vue.PluginFunction<never> = () => {}
123+
render(SomeComponent, {}, (localVue, store, router) => {
124+
localVue.use(ExamplePlugin)
125+
store.replaceState({foo: 'bar'})
126+
router.onError(error => console.log(error.message))
127+
})
128+
}
129+
130+
/*
131+
eslint
132+
testing-library/prefer-explicit-assert: "off",
133+
testing-library/no-wait-for-empty-callback: "off",
134+
testing-library/no-debug: "off",
135+
testing-library/prefer-screen-queries: "off",
136+
@typescript-eslint/unbound-method: "off",
137+
*/

‎types/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// this additional tsconfig is required by dtslint
2+
// see: https://github.com/Microsoft/dtslint#typestsconfigjson
3+
{
4+
"compilerOptions": {
5+
"module": "commonjs",
6+
"lib": ["es6", "dom"],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictNullChecks": true,
10+
"strictFunctionTypes": true,
11+
"noEmit": true,
12+
"baseUrl": ".",
13+
"paths": {
14+
"@testing-library/vue": ["."]
15+
}
16+
}
17+
}

‎types/tslint.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": ["dtslint/dtslint.json"],
3+
"rules": {
4+
"semicolon": false,
5+
"whitespace": false
6+
}
7+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /