-
Notifications
You must be signed in to change notification settings - Fork 470
Copied types from DefinitelyTyped into this repository #530
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dc8cc2a
Copied the newest .d.ts files from DefinitelyTyped
36c0231
Adjusted package.json to include type files and removed @types depend…
0045130
Merge branch 'master' into master
Lagily f02757e
Copied over DefinitelyTyped type tests
4184bb9
Added dtslint to check the types and type-tests
c876b1a
Adjusted the types to pass dtslint (removed unneeded jsdoc)
4330d34
Removed unneeded dependency 'conditional-type-check'
70d0975
Unified all waitForOptions types to one single type
82edc36
extended waitFor tests to better cover for the waitForOptions type
56cf2e4
Merge https://github.com/testing-library/dom-testing-library
bbe2ea1
Merge https://github.com/testing-library/dom-testing-library
430236e
Rebased and bumped TypeScript version (stable)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,122 @@ | ||
import { | ||
fireEvent, | ||
isInaccessible, | ||
queries, | ||
screen, | ||
waitFor, | ||
waitForElementToBeRemoved, | ||
} from '../index' | ||
|
||
const { | ||
getByText, | ||
queryByText, | ||
findByText, | ||
getAllByText, | ||
queryAllByText, | ||
findAllByText, | ||
queryAllByRole, | ||
queryByRole, | ||
findByRole, | ||
} = queries | ||
|
||
async function testQueries() { | ||
// element queries | ||
const element = document.createElement('div') | ||
getByText(element, 'foo') | ||
queryByText(element, 'foo') | ||
await findByText(element, 'foo') | ||
await findByText(element, 'foo', undefined, {timeout: 10}) | ||
getAllByText(element, 'bar') | ||
queryAllByText(element, 'bar') | ||
await findAllByText(element, 'bar') | ||
await findAllByText(element, 'bar', undefined, {timeout: 10}) | ||
|
||
// screen queries | ||
screen.getByText('foo') | ||
screen.queryByText('foo') | ||
await screen.findByText('foo') | ||
await screen.findByText('foo', undefined, {timeout: 10}) | ||
screen.debug(screen.getAllByText('bar')) | ||
screen.queryAllByText('bar') | ||
await screen.findAllByText('bar') | ||
await screen.findAllByText('bar', undefined, {timeout: 10}) | ||
} | ||
|
||
async function testByRole() { | ||
const element = document.createElement('button') | ||
element.setAttribute('aria-hidden', 'true') | ||
|
||
console.assert(queryByRole(element, 'button') === null) | ||
console.assert(queryByRole(element, 'button', {hidden: true}) !== null) | ||
|
||
console.assert(screen.queryByRole('button') === null) | ||
console.assert(screen.queryByRole('button', {hidden: true}) !== null) | ||
|
||
console.assert( | ||
(await findByRole(element, 'button', undefined, {timeout: 10})) === null, | ||
) | ||
console.assert( | ||
(await findByRole(element, 'button', {hidden: true}, {timeout: 10})) !== | ||
null, | ||
) | ||
|
||
console.assert( | ||
queryAllByRole(document.body, 'progressbar', {queryFallbacks: true}) | ||
.length === 1, | ||
) | ||
|
||
// `name` option | ||
console.assert(queryByRole(element, 'button', {name: 'Logout'}) === null) | ||
console.assert(queryByRole(element, 'button', {name: /^Log/}) === null) | ||
console.assert( | ||
queryByRole(element, 'button', { | ||
name: (name, element) => | ||
name === 'Login' && element.hasAttribute('disabled'), | ||
}) === null, | ||
) | ||
} | ||
|
||
function testA11yHelper() { | ||
const element = document.createElement('svg') | ||
console.assert(!isInaccessible(element)) | ||
} | ||
|
||
function eventTest() { | ||
fireEvent.popState(window, { | ||
location: 'http://www.example.com/?page=1', | ||
state: {page: 1}, | ||
}) | ||
|
||
// HTMLElement | ||
const element = document.createElement('div') | ||
fireEvent.click(getByText(element, 'foo')) | ||
|
||
// ChildNode | ||
const child = document.createElement('div') | ||
element.appendChild(child) | ||
if (!element.firstChild) { | ||
// Narrow Type | ||
throw new Error(`Can't find firstChild`) | ||
} | ||
fireEvent.click(element.firstChild) | ||
} | ||
|
||
async function testWaitFors() { | ||
const element = document.createElement('div') | ||
|
||
await waitFor(() => getByText(element, 'apple')) | ||
await waitFor(() => getAllByText(element, 'apple')) | ||
const result: HTMLSpanElement = await waitFor(() => | ||
getByText(element, 'apple'), | ||
) | ||
if (!result) { | ||
// Use value | ||
throw new Error(`Can't find result`) | ||
} | ||
|
||
element.innerHTML = '<span>apple</span>' | ||
|
||
await waitForElementToBeRemoved(() => getByText(element, 'apple')) | ||
await waitForElementToBeRemoved(getByText(element, 'apple')) | ||
await waitForElementToBeRemoved(getAllByText(element, 'apple')) | ||
} |
This file contains hidden or 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,12 @@ | ||
export interface Config { | ||
testIdAttribute: string; | ||
asyncWrapper(cb: (...args: any[]) => any): Promise<any>; | ||
asyncUtilTimeout: number; | ||
defaultHidden: boolean; | ||
} | ||
|
||
export interface ConfigFn { | ||
(existingConfig: Config): Partial<Config>; | ||
} | ||
|
||
export function configure(configDelta: Partial<Config> | ConfigFn): void; |
This file contains hidden or 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,95 @@ | ||
export type EventType = | ||
| 'copy' | ||
| 'cut' | ||
| 'paste' | ||
| 'compositionEnd' | ||
| 'compositionStart' | ||
| 'compositionUpdate' | ||
| 'keyDown' | ||
| 'keyPress' | ||
| 'keyUp' | ||
| 'focus' | ||
| 'blur' | ||
| 'focusIn' | ||
| 'focusOut' | ||
| 'change' | ||
| 'input' | ||
| 'invalid' | ||
| 'submit' | ||
| 'reset' | ||
| 'click' | ||
| 'contextMenu' | ||
| 'dblClick' | ||
| 'drag' | ||
| 'dragEnd' | ||
| 'dragEnter' | ||
| 'dragExit' | ||
| 'dragLeave' | ||
| 'dragOver' | ||
| 'dragStart' | ||
| 'drop' | ||
| 'mouseDown' | ||
| 'mouseEnter' | ||
| 'mouseLeave' | ||
| 'mouseMove' | ||
| 'mouseOut' | ||
| 'mouseOver' | ||
| 'mouseUp' | ||
| 'popState' | ||
| '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' | ||
| 'pointerOver' | ||
| 'pointerEnter' | ||
| 'pointerDown' | ||
| 'pointerMove' | ||
| 'pointerUp' | ||
| 'pointerCancel' | ||
| 'pointerOut' | ||
| 'pointerLeave' | ||
| 'gotPointerCapture' | ||
| 'lostPointerCapture'; | ||
|
||
export type FireFunction = (element: Document | Element | Window | Node, event: Event) => boolean; | ||
export type FireObject = { | ||
[K in EventType]: (element: Document | Element | Window | Node, options?: {}) => boolean; | ||
}; | ||
export type CreateObject = { | ||
[K in EventType]: (element: Document | Element | Window | Node, options?: {}) => Event; | ||
}; | ||
|
||
export const createEvent: CreateObject; | ||
export const fireEvent: FireFunction & FireObject; |
This file contains hidden or 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 hidden or 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,30 @@ | ||
import { Matcher } from './matches'; | ||
import * as queries from './queries'; | ||
|
||
export type BoundFunction<T> = T extends ( | ||
attribute: string, | ||
element: HTMLElement, | ||
text: infer P, | ||
options: infer Q, | ||
) => infer R | ||
? (text: P, options?: Q) => R | ||
: T extends (a1: any, text: infer P, options: infer Q, waitForElementOptions: infer W) => infer R | ||
? (text: P, options?: Q, waitForElementOptions?: W) => R | ||
: 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 type Query = ( | ||
container: HTMLElement, | ||
...args: any[] | ||
) => Error | Promise<HTMLElement[]> | Promise<HTMLElement> | HTMLElement[] | HTMLElement | null; | ||
|
||
export interface Queries { | ||
[T: string]: Query; | ||
} | ||
|
||
export function getQueriesForElement<T extends Queries = typeof queries>( | ||
element: HTMLElement, | ||
queriesToBind?: T, | ||
): BoundFunctions<T>; |
This file contains hidden or 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,24 @@ | ||
// TypeScript Version: 3.1 | ||
|
||
import { getQueriesForElement } from './get-queries-for-element'; | ||
import * as queries from './queries'; | ||
import * as queryHelpers from './query-helpers'; | ||
|
||
declare const within: typeof getQueriesForElement; | ||
export { queries, queryHelpers, within }; | ||
|
||
export * from './queries'; | ||
export * from './query-helpers'; | ||
export * from './screen'; | ||
export * from './wait'; | ||
export * from './wait-for'; | ||
export * from './wait-for-dom-change'; | ||
export * from './wait-for-element'; | ||
export * from './wait-for-element-to-be-removed'; | ||
export * from './matches'; | ||
export * from './get-node-text'; | ||
export * from './events'; | ||
export * from './get-queries-for-element'; | ||
export * from './pretty-dom'; | ||
export * from './role-helpers'; | ||
export * from './config'; |
This file contains hidden or 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,29 @@ | ||
export type MatcherFunction = (content: string, element: HTMLElement) => boolean; | ||
export type Matcher = string | RegExp | MatcherFunction; | ||
|
||
export type NormalizerFn = (text: string) => string; | ||
|
||
export interface MatcherOptions { | ||
exact?: boolean; | ||
/** Use normalizer with getDefaultNormalizer instead */ | ||
trim?: boolean; | ||
/** Use normalizer with getDefaultNormalizer instead */ | ||
collapseWhitespace?: boolean; | ||
normalizer?: NormalizerFn; | ||
} | ||
|
||
export type Match = ( | ||
textToMatch: string, | ||
node: HTMLElement | null, | ||
matcher: Matcher, | ||
options?: MatcherOptions, | ||
) => boolean; | ||
|
||
export interface DefaultNormalizerOptions { | ||
trim?: boolean; | ||
collapseWhitespace?: boolean; | ||
} | ||
|
||
export function getDefaultNormalizer(options?: DefaultNormalizerOptions): NormalizerFn; | ||
|
||
// N.B. Don't expose fuzzyMatches + matches here: they're not public API |
This file contains hidden or 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 @@ | ||
import { OptionsReceived } from 'pretty-format'; | ||
|
||
export function prettyDOM(dom?: Element | HTMLDocument, maxLength?: number, options?: OptionsReceived): string | false; | ||
export function logDOM(dom?: Element | HTMLDocument, maxLength?: number, options?: OptionsReceived): void; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.