Skip to content

Commit 56b768d

Browse files
maddijoyceKent C. Dodds
authored andcommitted
feat(TS): add typescript definitions (#37)
* Add type definitions. * Fixing dtslint issues. (Also making lint config match prettier) * Adding myself as contributor
1 parent b41b2e7 commit 56b768d

15 files changed

+246
-4
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@
200200
"contributions": [
201201
"code"
202202
]
203+
},
204+
{
205+
"login": "maddijoyce",
206+
"name": "Maddi Joyce",
207+
"avatar_url": "https://avatars2.githubusercontent.com/u/2224291?v=4",
208+
"profile": "http://www.maddijoyce.com",
209+
"contributions": [
210+
"code"
211+
]
203212
}
204213
]
205214
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[![downloads][downloads-badge]][npmtrends]
1717
[![MIT License][license-badge]][license]
1818

19-
[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors)
19+
[![All Contributors](https://img.shields.io/badge/all_contributors-20-orange.svg?style=flat-square)](#contributors)
2020
[![PRs Welcome][prs-badge]][prs]
2121
[![Code of Conduct][coc-badge]][coc]
2222

@@ -862,7 +862,7 @@ Thanks goes to these people ([emoji key][emojis]):
862862
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=kentcdodds "Tests") | [<img src="https://avatars1.githubusercontent.com/u/2430381?v=4" width="100px;"/><br /><sub><b>Ryan Castner</b></sub>](http://audiolion.github.io)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=audiolion "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/8008023?v=4" width="100px;"/><br /><sub><b>Daniel Sandiego</b></sub>](https://www.dnlsandiego.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dnlsandiego "Code") | [<img src="https://avatars2.githubusercontent.com/u/12592677?v=4" width="100px;"/><br /><sub><b>Paweł Mikołajczyk</b></sub>](https://github.com/Miklet)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=Miklet "Code") | [<img src="https://avatars3.githubusercontent.com/u/464978?v=4" width="100px;"/><br /><sub><b>Alejandro Ñáñez Ortiz</b></sub>](http://co.linkedin.com/in/alejandronanez/)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=alejandronanez "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/1402095?v=4" width="100px;"/><br /><sub><b>Matt Parrish</b></sub>](https://github.com/pbomb)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Apbomb "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=pbomb "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=pbomb "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=pbomb "Tests") | [<img src="https://avatars1.githubusercontent.com/u/1288694?v=4" width="100px;"/><br /><sub><b>Justin Hall</b></sub>](https://github.com/wKovacs64)<br />[📦](#platform-wKovacs64 "Packaging/porting to new platform") |
863863
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
864864
| [<img src="https://avatars1.githubusercontent.com/u/1241511?s=460&v=4" width="100px;"/><br /><sub><b>Anto Aravinth</b></sub>](https://github.com/antoaravinth)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Tests") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/3462296?v=4" width="100px;"/><br /><sub><b>Jonah Moses</b></sub>](https://github.com/JonahMoses)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JonahMoses "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/4002543?v=4" width="100px;"/><br /><sub><b>Łukasz Gandecki</b></sub>](http://team.thebrain.pro)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Tests") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/498274?v=4" width="100px;"/><br /><sub><b>Ivan Babak</b></sub>](https://sompylasar.github.io)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Asompylasar "Bug reports") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=sompylasar "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=sompylasar "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/4439618?v=4" width="100px;"/><br /><sub><b>Jesse Day</b></sub>](https://github.com/jday3)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jday3 "Code") | [<img src="https://avatars0.githubusercontent.com/u/15199?v=4" width="100px;"/><br /><sub><b>Ernesto García</b></sub>](http://gnapse.github.io)<br />[💬](#question-gnapse "Answering Questions") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=gnapse "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=gnapse "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/2747424?v=4" width="100px;"/><br /><sub><b>Josef Maxx Blake</b></sub>](http://jomaxx.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Tests") |
865-
| [<img src="https://avatars3.githubusercontent.com/u/725236?v=4" width="100px;"/><br /><sub><b>Alex Cook</b></sub>](https://github.com/alecook)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=alecook "Documentation") [💡](#example-alecook "Examples") | [<img src="https://avatars3.githubusercontent.com/u/10348212?v=4" width="100px;"/><br /><sub><b>Daniel Cook</b></sub>](https://github.com/dfcook)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Tests") | [<img src="https://avatars2.githubusercontent.com/u/21194045?s=400&v=4" width="100px;"/><br /><sub><b>Thomas Chia</b></sub>](https://github.com/thchia)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Athchia "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=thchia "Code") | [<img src="https://avatars1.githubusercontent.com/u/28659384?v=4" width="100px;"/><br /><sub><b>Tim Deschryver</b></sub>](https://github.com/tdeschryver)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Tests") | [<img src="https://avatars3.githubusercontent.com/u/1571667?v=4" width="100px;"/><br /><sub><b>Alex Krolick</b></sub>](https://alexkrolick.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=alexkrolick "Code") |
865+
| [<img src="https://avatars3.githubusercontent.com/u/725236?v=4" width="100px;"/><br /><sub><b>Alex Cook</b></sub>](https://github.com/alecook)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=alecook "Documentation") [💡](#example-alecook "Examples") | [<img src="https://avatars3.githubusercontent.com/u/10348212?v=4" width="100px;"/><br /><sub><b>Daniel Cook</b></sub>](https://github.com/dfcook)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Tests") | [<img src="https://avatars2.githubusercontent.com/u/21194045?s=400&v=4" width="100px;"/><br /><sub><b>Thomas Chia</b></sub>](https://github.com/thchia)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Athchia "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=thchia "Code") | [<img src="https://avatars1.githubusercontent.com/u/28659384?v=4" width="100px;"/><br /><sub><b>Tim Deschryver</b></sub>](https://github.com/tdeschryver)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Tests") | [<img src="https://avatars3.githubusercontent.com/u/1571667?v=4" width="100px;"/><br /><sub><b>Alex Krolick</b></sub>](https://alexkrolick.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=alexkrolick "Code") | [<img src="https://avatars2.githubusercontent.com/u/2224291?v=4" width="100px;"/><br /><sub><b>Maddi Joyce</b></sub>](http://www.maddijoyce.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=maddijoyce "Code") |
866866

867867
<!-- ALL-CONTRIBUTORS-LIST:END -->
868868

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.0-semantically-released",
44
"description": "Simple and complete DOM testing utilities that encourage good testing practices.",
55
"main": "dist/index.js",
6+
"typings": "typings",
67
"keywords": [
78
"testing",
89
"ui",
@@ -27,10 +28,12 @@
2728
"test:update": "npm test -- --updateSnapshot --coverage",
2829
"validate": "kcd-scripts validate",
2930
"setup": "npm install && npm run validate -s",
30-
"precommit": "kcd-scripts precommit"
31+
"precommit": "kcd-scripts precommit",
32+
"dtslint": "dtslint typings"
3133
},
3234
"files": [
3335
"dist",
36+
"typings",
3437
"extend-expect.js"
3538
],
3639
"dependencies": {
@@ -40,6 +43,7 @@
4043
"wait-for-expect": "^0.4.0"
4144
},
4245
"devDependencies": {
46+
"dtslint": "^0.3.0",
4347
"jest-in-case": "^1.0.2",
4448
"kcd-scripts": "^0.37.0"
4549
},

src/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const {
1919
const eventMap = {
2020
// Clipboard Events
2121
copy: {
22-
EventType: CompositionEvent,
22+
EventType: ClipboardEvent,
2323
defaultInit: {bubbles: true, cancelable: true},
2424
},
2525
cut: {

typings/bind-element-to-queries.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Matcher} from 'matches'
2+
import * as queries from './queries'
3+
4+
export type BoundFunction<T> = T extends (
5+
a1: any,
6+
text: infer P,
7+
options: infer Q,
8+
) => infer R
9+
? (text: P, options?: Q) => R
10+
: never
11+
export type BoundFunctions<T> = {[P in keyof T]: BoundFunction<T[P]>}
12+
13+
export function bindElementToQueries(
14+
element: HTMLElement,
15+
): BoundFunctions<typeof queries>

typings/events.d.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
export type EventType =
2+
| 'copy'
3+
| 'cut'
4+
| 'paste'
5+
| 'compositionEnd'
6+
| 'compositionStart'
7+
| 'compositionUpdate'
8+
| 'keyDown'
9+
| 'keyPress'
10+
| 'keyUp'
11+
| 'focus'
12+
| 'blur'
13+
| 'change'
14+
| 'input'
15+
| 'invalid'
16+
| 'submit'
17+
| 'click'
18+
| 'contextMenu'
19+
| 'dblClick'
20+
| 'drag'
21+
| 'dragEnd'
22+
| 'dragEnter'
23+
| 'dragExit'
24+
| 'dragLeave'
25+
| 'dragOver'
26+
| 'dragStart'
27+
| 'drop'
28+
| 'mouseDown'
29+
| 'mouseEnter'
30+
| 'mouseLeave'
31+
| 'mouseMove'
32+
| 'mouseOut'
33+
| 'mouseOver'
34+
| 'mouseUp'
35+
| 'select'
36+
| 'touchCancel'
37+
| 'touchEnd'
38+
| 'touchMove'
39+
| 'touchStart'
40+
| 'scroll'
41+
| 'wheel'
42+
| 'abort'
43+
| 'canPlay'
44+
| 'canPlayThrough'
45+
| 'durationChange'
46+
| 'emptied'
47+
| 'encrypted'
48+
| 'ended'
49+
| 'loadedData'
50+
| 'loadedMetadata'
51+
| 'loadStart'
52+
| 'pause'
53+
| 'play'
54+
| 'playing'
55+
| 'progress'
56+
| 'rateChange'
57+
| 'seeked'
58+
| 'seeking'
59+
| 'stalled'
60+
| 'suspend'
61+
| 'timeUpdate'
62+
| 'volumeChange'
63+
| 'waiting'
64+
| 'load'
65+
| 'error'
66+
| 'animationStart'
67+
| 'animationEnd'
68+
| 'animationIteration'
69+
| 'transitionEnd'
70+
| 'doubleClick'
71+
72+
export type FireFunction = (element: HTMLElement, event: Event) => boolean
73+
export type FireObject = {
74+
[K in EventType]: (element: HTMLElement, options?: {}) => boolean
75+
}
76+
77+
export const fireEvent: FireFunction & FireObject

typings/get-node-text.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function getNodeText(node: HTMLElement): string

typings/index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// TypeScript Version: 2.8
2+
import * as queries from './queries'
3+
4+
export {queries}
5+
6+
export * from './queries'
7+
export * from './wait'
8+
export * from './wait-for-element'
9+
export * from './matches'
10+
export * from './get-node-text'
11+
export * from './events'
12+
export * from './bind-element-to-queries'
13+
export * from './pretty-dom'

typings/matches.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export type MatcherFunction = (content: string, element: HTMLElement) => boolean
2+
export type Matcher = string | RegExp | MatcherFunction
3+
export interface MatcherOptions {
4+
exact?: boolean
5+
trim?: boolean
6+
collapseWhitespace?: boolean
7+
}
8+
9+
export type Match = (
10+
textToMatch: string,
11+
node: HTMLElement | null,
12+
matcher: Matcher,
13+
options?: MatcherOptions,
14+
) => boolean
15+
16+
export const fuzzyMatches: Match
17+
export const matches: Match

typings/pretty-dom.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function prettyDOM(
2+
element: HTMLElement,
3+
maxLength?: number,
4+
): string | false

0 commit comments

Comments
 (0)