diff --git a/.all-contributorsrc b/.all-contributorsrc
index 5d5a66b6..d984844d 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -200,6 +200,15 @@
"contributions": [
"code"
]
+ },
+ {
+ "login": "maddijoyce",
+ "name": "Maddi Joyce",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/2224291?v=4",
+ "profile": "http://www.maddijoyce.com",
+ "contributions": [
+ "code"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 59650138..ace845d5 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]
-[](#contributors)
+[](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Code of Conduct][coc-badge]][coc]
@@ -841,7 +841,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [
Kent C. Dodds](https://kentcdodds.com)
[π»](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") | [
Ryan Castner](http://audiolion.github.io)
[π](https://github.com/kentcdodds/dom-testing-library/commits?author=audiolion "Documentation") | [
Daniel Sandiego](https://www.dnlsandiego.com)
[π»](https://github.com/kentcdodds/dom-testing-library/commits?author=dnlsandiego "Code") | [
PaweΕ MikoΕajczyk](https://github.com/Miklet)
[π»](https://github.com/kentcdodds/dom-testing-library/commits?author=Miklet "Code") | [
Alejandro ΓÑñez Ortiz](http://co.linkedin.com/in/alejandronanez/)
[π](https://github.com/kentcdodds/dom-testing-library/commits?author=alejandronanez "Documentation") | [
Matt Parrish](https://github.com/pbomb)
[π](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") | [
Justin Hall](https://github.com/wKovacs64)
[π¦](#platform-wKovacs64 "Packaging/porting to new platform") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [
Anto Aravinth](https://github.com/antoaravinth)
[π»](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") | [
Jonah Moses](https://github.com/JonahMoses)
[π](https://github.com/kentcdodds/dom-testing-library/commits?author=JonahMoses "Documentation") | [
Εukasz Gandecki](http://team.thebrain.pro)
[π»](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") | [
Ivan Babak](https://sompylasar.github.io)
[π](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") | [
Jesse Day](https://github.com/jday3)
[π»](https://github.com/kentcdodds/dom-testing-library/commits?author=jday3 "Code") | [
Ernesto GarcΓa](http://gnapse.github.io)
[π¬](#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") | [
Josef Maxx Blake](http://jomaxx.com)
[π»](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") |
-| [
Alex Cook](https://github.com/alecook)
[π](https://github.com/kentcdodds/dom-testing-library/commits?author=alecook "Documentation") [π‘](#example-alecook "Examples") | [
Daniel Cook](https://github.com/dfcook)
[π»](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") | [
Thomas Chia](https://github.com/thchia)
[π](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Athchia "Bug reports") [π»](https://github.com/kentcdodds/dom-testing-library/commits?author=thchia "Code") | [
Tim Deschryver](https://github.com/tdeschryver)
[π»](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Code") [β οΈ](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Tests") | [
Alex Krolick](https://alexkrolick.com)
[π»](https://github.com/kentcdodds/dom-testing-library/commits?author=alexkrolick "Code") |
+| [
Alex Cook](https://github.com/alecook)
[π](https://github.com/kentcdodds/dom-testing-library/commits?author=alecook "Documentation") [π‘](#example-alecook "Examples") | [
Daniel Cook](https://github.com/dfcook)
[π»](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") | [
Thomas Chia](https://github.com/thchia)
[π](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Athchia "Bug reports") [π»](https://github.com/kentcdodds/dom-testing-library/commits?author=thchia "Code") | [
Tim Deschryver](https://github.com/tdeschryver)
[π»](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Code") [β οΈ](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Tests") | [
Alex Krolick](https://alexkrolick.com)
[π»](https://github.com/kentcdodds/dom-testing-library/commits?author=alexkrolick "Code") | [
Maddi Joyce](http://www.maddijoyce.com)
[π»](https://github.com/kentcdodds/dom-testing-library/commits?author=maddijoyce "Code") |
diff --git a/package.json b/package.json
index b3867852..2d8e0333 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "0.0.0-semantically-released",
"description": "Simple and complete DOM testing utilities that encourage good testing practices.",
"main": "dist/index.js",
+ "typings": "typings",
"keywords": [
"testing",
"ui",
@@ -27,10 +28,12 @@
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate",
"setup": "npm install && npm run validate -s",
- "precommit": "kcd-scripts precommit"
+ "precommit": "kcd-scripts precommit",
+ "dtslint": "dtslint typings"
},
"files": [
"dist",
+ "typings",
"extend-expect.js"
],
"dependencies": {
@@ -40,6 +43,7 @@
"wait-for-expect": "^0.4.0"
},
"devDependencies": {
+ "dtslint": "^0.3.0",
"jest-in-case": "^1.0.2",
"kcd-scripts": "^0.37.0"
},
diff --git a/src/events.js b/src/events.js
index ad5a8e33..c9adc34e 100644
--- a/src/events.js
+++ b/src/events.js
@@ -19,7 +19,7 @@ const {
const eventMap = {
// Clipboard Events
copy: {
- EventType: CompositionEvent,
+ EventType: ClipboardEvent,
defaultInit: {bubbles: true, cancelable: true},
},
cut: {
diff --git a/typings/bind-element-to-queries.d.ts b/typings/bind-element-to-queries.d.ts
new file mode 100644
index 00000000..432b638c
--- /dev/null
+++ b/typings/bind-element-to-queries.d.ts
@@ -0,0 +1,15 @@
+import {Matcher} from 'matches'
+import * as queries from './queries'
+
+export type BoundFunction = T extends (
+ a1: any,
+ text: infer P,
+ options: infer Q,
+) => infer R
+ ? (text: P, options?: Q) => R
+ : never
+export type BoundFunctions = {[P in keyof T]: BoundFunction}
+
+export function bindElementToQueries(
+ element: HTMLElement,
+): BoundFunctions
diff --git a/typings/events.d.ts b/typings/events.d.ts
new file mode 100644
index 00000000..a11bd3c7
--- /dev/null
+++ b/typings/events.d.ts
@@ -0,0 +1,77 @@
+export type EventType =
+ | 'copy'
+ | 'cut'
+ | 'paste'
+ | 'compositionEnd'
+ | 'compositionStart'
+ | 'compositionUpdate'
+ | 'keyDown'
+ | 'keyPress'
+ | 'keyUp'
+ | 'focus'
+ | 'blur'
+ | 'change'
+ | 'input'
+ | 'invalid'
+ | 'submit'
+ | 'click'
+ | 'contextMenu'
+ | 'dblClick'
+ | 'drag'
+ | 'dragEnd'
+ | 'dragEnter'
+ | 'dragExit'
+ | 'dragLeave'
+ | 'dragOver'
+ | 'dragStart'
+ | 'drop'
+ | 'mouseDown'
+ | 'mouseEnter'
+ | 'mouseLeave'
+ | 'mouseMove'
+ | 'mouseOut'
+ | 'mouseOver'
+ | 'mouseUp'
+ | 'select'
+ | 'touchCancel'
+ | 'touchEnd'
+ | 'touchMove'
+ | 'touchStart'
+ | 'scroll'
+ | 'wheel'
+ | 'abort'
+ | 'canPlay'
+ | 'canPlayThrough'
+ | 'durationChange'
+ | 'emptied'
+ | 'encrypted'
+ | 'ended'
+ | 'loadedData'
+ | 'loadedMetadata'
+ | 'loadStart'
+ | 'pause'
+ | 'play'
+ | 'playing'
+ | 'progress'
+ | 'rateChange'
+ | 'seeked'
+ | 'seeking'
+ | 'stalled'
+ | 'suspend'
+ | 'timeUpdate'
+ | 'volumeChange'
+ | 'waiting'
+ | 'load'
+ | 'error'
+ | 'animationStart'
+ | 'animationEnd'
+ | 'animationIteration'
+ | 'transitionEnd'
+ | 'doubleClick'
+
+export type FireFunction = (element: HTMLElement, event: Event) => boolean
+export type FireObject = {
+ [K in EventType]: (element: HTMLElement, options?: {}) => boolean
+}
+
+export const fireEvent: FireFunction & FireObject
diff --git a/typings/get-node-text.d.ts b/typings/get-node-text.d.ts
new file mode 100644
index 00000000..3f01b629
--- /dev/null
+++ b/typings/get-node-text.d.ts
@@ -0,0 +1 @@
+export function getNodeText(node: HTMLElement): string
diff --git a/typings/index.d.ts b/typings/index.d.ts
new file mode 100644
index 00000000..44f58402
--- /dev/null
+++ b/typings/index.d.ts
@@ -0,0 +1,13 @@
+// TypeScript Version: 2.8
+import * as queries from './queries'
+
+export {queries}
+
+export * from './queries'
+export * from './wait'
+export * from './wait-for-element'
+export * from './matches'
+export * from './get-node-text'
+export * from './events'
+export * from './bind-element-to-queries'
+export * from './pretty-dom'
diff --git a/typings/matches.d.ts b/typings/matches.d.ts
new file mode 100644
index 00000000..af89af82
--- /dev/null
+++ b/typings/matches.d.ts
@@ -0,0 +1,17 @@
+export type MatcherFunction = (content: string, element: HTMLElement) => boolean
+export type Matcher = string | RegExp | MatcherFunction
+export interface MatcherOptions {
+ exact?: boolean
+ trim?: boolean
+ collapseWhitespace?: boolean
+}
+
+export type Match = (
+ textToMatch: string,
+ node: HTMLElement | null,
+ matcher: Matcher,
+ options?: MatcherOptions,
+) => boolean
+
+export const fuzzyMatches: Match
+export const matches: Match
diff --git a/typings/pretty-dom.d.ts b/typings/pretty-dom.d.ts
new file mode 100644
index 00000000..23738431
--- /dev/null
+++ b/typings/pretty-dom.d.ts
@@ -0,0 +1,4 @@
+export function prettyDOM(
+ element: HTMLElement,
+ maxLength?: number,
+): string | false
diff --git a/typings/queries.d.ts b/typings/queries.d.ts
new file mode 100644
index 00000000..2d26bd3f
--- /dev/null
+++ b/typings/queries.d.ts
@@ -0,0 +1,66 @@
+import {Matcher, MatcherOptions} from './matches'
+
+export interface SelectorMatcherOptions extends MatcherOptions {
+ selector?: string
+}
+
+export type QueryByAttribute = (
+ container: HTMLElement,
+ id: Matcher,
+ options?: MatcherOptions,
+) => HTMLElement | null
+
+export type AllByAttribute = (
+ container: HTMLElement,
+ id: Matcher,
+ options?: MatcherOptions,
+) => [HTMLElement]
+
+export type GetByAttribute = (
+ container: HTMLElement,
+ id: Matcher,
+ options?: MatcherOptions,
+) => HTMLElement
+
+export type QueryByText = (
+ container: HTMLElement,
+ id: Matcher,
+ options?: SelectorMatcherOptions,
+) => HTMLElement | null
+
+export type AllByText = (
+ container: HTMLElement,
+ id: Matcher,
+ options?: SelectorMatcherOptions,
+) => [HTMLElement]
+
+export type GetByText = (
+ container: HTMLElement,
+ id: Matcher,
+ options?: SelectorMatcherOptions,
+) => HTMLElement
+
+export const queryByPlaceholderText: QueryByAttribute
+export const queryAllByPlaceholderText: AllByAttribute
+export const getByPlaceholderText: GetByAttribute
+export const getAllByPlaceholderText: AllByAttribute
+export const queryByText: QueryByText
+export const queryAllByText: AllByText
+export const getByText: GetByText
+export const getAllByText: AllByText
+export const queryByLabelText: QueryByText
+export const queryAllByLabelText: AllByText
+export const getByLabelText: GetByText
+export const getAllByLabelText: AllByText
+export const queryByAltText: QueryByAttribute
+export const queryAllByAltText: AllByAttribute
+export const getByAltText: GetByAttribute
+export const getAllByAltText: AllByAttribute
+export const queryByTestId: QueryByAttribute
+export const queryAllByTestId: AllByAttribute
+export const getByTestId: GetByAttribute
+export const getAllByTestId: AllByAttribute
+export const queryByTitle: QueryByAttribute
+export const queryAllByTitle: AllByAttribute
+export const getByTitle: GetByAttribute
+export const getAllByTitle: AllByAttribute
diff --git a/typings/tsconfig.json b/typings/tsconfig.json
new file mode 100644
index 00000000..81e4f72b
--- /dev/null
+++ b/typings/tsconfig.json
@@ -0,0 +1,14 @@
+{
+ "compilerOptions": {
+ "module": "commonjs",
+ "lib": ["es6", "dom"],
+ "noImplicitAny": true,
+ "noImplicitThis": true,
+ "strictFunctionTypes": true,
+ "strictNullChecks": true,
+ "noEmit": true,
+
+ "baseUrl": ".",
+ "paths": {"dom-testing-library": ["."]}
+ }
+}
diff --git a/typings/tslint.json b/typings/tslint.json
new file mode 100644
index 00000000..286a004f
--- /dev/null
+++ b/typings/tslint.json
@@ -0,0 +1,7 @@
+{
+ "extends": "dtslint/dtslint.json",
+ "rules": {
+ "semicolon": [true, "never"],
+ "whitespace": [false]
+ }
+}
diff --git a/typings/wait-for-element.d.ts b/typings/wait-for-element.d.ts
new file mode 100644
index 00000000..ad5b14b7
--- /dev/null
+++ b/typings/wait-for-element.d.ts
@@ -0,0 +1,8 @@
+export function waitForElement(
+ callback?: () => T,
+ options?: {
+ container?: HTMLElement
+ timeout?: number
+ mutationObserverOptions?: MutationObserverInit
+ },
+): Promise
diff --git a/typings/wait.d.ts b/typings/wait.d.ts
new file mode 100644
index 00000000..cb102637
--- /dev/null
+++ b/typings/wait.d.ts
@@ -0,0 +1,7 @@
+export function wait(
+ callback?: () => void,
+ options?: {
+ timeout?: number
+ interval?: number
+ },
+): Promise