Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TS): add typescript definitions (#37)
* Add type definitions. * Fixing dtslint issues. (Also making lint config match prettier) * Adding myself as contributor
- Loading branch information
1 parent
b41b2e7
commit 56b768d
Showing
15 changed files
with
246 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Matcher} from 'matches' | ||
import * as queries from './queries' | ||
|
||
export type BoundFunction<T> = T extends ( | ||
a1: any, | ||
text: infer P, | ||
options: infer Q, | ||
) => infer R | ||
? (text: P, options?: Q) => R | ||
: never | ||
export type BoundFunctions<T> = {[P in keyof T]: BoundFunction<T[P]>} | ||
|
||
export function bindElementToQueries( | ||
element: HTMLElement, | ||
): BoundFunctions<typeof queries> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export function getNodeText(node: HTMLElement): string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function prettyDOM( | ||
element: HTMLElement, | ||
maxLength?: number, | ||
): string | false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": ["."]} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"semicolon": [true, "never"], | ||
"whitespace": [false] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function waitForElement<T>( | ||
callback?: () => T, | ||
options?: { | ||
container?: HTMLElement | ||
timeout?: number | ||
mutationObserverOptions?: MutationObserverInit | ||
}, | ||
): Promise<T | undefined> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function wait( | ||
callback?: () => void, | ||
options?: { | ||
timeout?: number | ||
interval?: number | ||
}, | ||
): Promise<void> |