`.
+ */
+ queryFallbacks?: boolean
+ /**
+ * Only considers elements with the specified accessible name.
+ */
+ name?:
+ | string
+ | RegExp
+ | ((accessibleName: string, element: Element) => boolean)
+}
+
function queryAllByRole(
- container,
- role,
+ container: HTMLElement,
+ role: Matcher,
{
exact = true,
collapseWhitespace,
@@ -29,7 +57,7 @@ function queryAllByRole(
normalizer,
queryFallbacks = false,
selected,
- } = {},
+ }: ByRoleOptions = {},
) {
checkContainerType(container)
const matcher = exact ? matches : fuzzyMatches
@@ -52,7 +80,7 @@ function queryAllByRole(
}
return Array.from(container.querySelectorAll('*'))
- .filter(node => {
+ .filter((node: HTMLElement) => {
const isRoleSpecifiedExplicitly = node.hasAttribute('role')
if (isRoleSpecifiedExplicitly) {
@@ -85,14 +113,14 @@ function queryAllByRole(
// don't care if aria attributes are unspecified
return true
})
- .filter(element => {
+ .filter((element: HTMLElement) => {
return hidden === false
? isInaccessible(element, {
isSubtreeInaccessible: cachedIsSubtreeInaccessible,
}) === false
: true
})
- .filter(element => {
+ .filter((element: HTMLElement) => {
if (name === undefined) {
// Don't care
return true
@@ -104,7 +132,7 @@ function queryAllByRole(
name,
text => text,
)
- })
+ }) as HTMLElement[]
}
const getMultipleError = (c, role) =>
@@ -113,16 +141,17 @@ const getMultipleError = (c, role) =>
const getMissingError = (
container,
role,
- {hidden = getConfig().defaultHidden, name} = {},
+ {hidden = getConfig().defaultHidden, name}: ByRoleOptions = {},
) => {
if (getConfig()._disableExpensiveErrorDiagnostics) {
return `Unable to find role="${role}"`
}
let roles = ''
- Array.from(container.children).forEach(childElement => {
+ Array.from(container.children).forEach((childElement: HTMLElement) => {
roles += prettyRoles(childElement, {
hidden,
+ // @ts-ignore FIXME remove this code? prettyRoles does not seem handle 'includeName'
includeName: name !== undefined,
})
})
diff --git a/src/queries/test-id.js b/src/queries/test-id.ts
similarity index 71%
rename from src/queries/test-id.js
rename to src/queries/test-id.ts
index f2ef5a9d..2ab618d5 100644
--- a/src/queries/test-id.js
+++ b/src/queries/test-id.ts
@@ -1,12 +1,22 @@
import {checkContainerType} from '../helpers'
import {wrapAllByQueryWithSuggestion} from '../query-helpers'
-import {queryAllByAttribute, getConfig, buildQueries} from './all-utils'
+import {
+ queryAllByAttribute,
+ getConfig,
+ buildQueries,
+ Matcher,
+ MatcherOptions,
+} from './all-utils'
const getTestIdAttribute = () => getConfig().testIdAttribute
-function queryAllByTestId(...args) {
- checkContainerType(...args)
- return queryAllByAttribute(getTestIdAttribute(), ...args)
+function queryAllByTestId(
+ container: HTMLElement,
+ testId: Matcher,
+ options?: MatcherOptions,
+) {
+ checkContainerType(container)
+ return queryAllByAttribute(getTestIdAttribute(), container, testId, options)
}
const getMultipleError = (c, id) =>
diff --git a/src/queries/text.js b/src/queries/text.ts
similarity index 80%
rename from src/queries/text.js
rename to src/queries/text.ts
index 903bba25..5cbdfe46 100644
--- a/src/queries/text.js
+++ b/src/queries/text.ts
@@ -1,4 +1,7 @@
-import {wrapAllByQueryWithSuggestion} from '../query-helpers'
+import {
+ SelectorMatcherOptions,
+ wrapAllByQueryWithSuggestion,
+} from '../query-helpers'
import {checkContainerType} from '../helpers'
import {DEFAULT_IGNORE_TAGS} from '../config'
import {
@@ -7,11 +10,16 @@ import {
makeNormalizer,
getNodeText,
buildQueries,
+ Matcher,
} from './all-utils'
+interface ByTextSelectorMatcherOptions extends SelectorMatcherOptions {
+ ignore?: string
+}
+
function queryAllByText(
- container,
- text,
+ container: HTMLElement,
+ text: Matcher,
{
selector = '*',
exact = true,
@@ -19,7 +27,7 @@ function queryAllByText(
trim,
ignore = DEFAULT_IGNORE_TAGS,
normalizer,
- } = {},
+ }: ByTextSelectorMatcherOptions = {},
) {
checkContainerType(container)
const matcher = exact ? matches : fuzzyMatches
@@ -30,7 +38,9 @@ function queryAllByText(
}
return [...baseArray, ...Array.from(container.querySelectorAll(selector))]
.filter(node => !ignore || !node.matches(ignore))
- .filter(node => matcher(getNodeText(node), node, text, matchNormalizer))
+ .filter(node =>
+ matcher(getNodeText(node), node, text, matchNormalizer),
+ ) as HTMLElement[]
}
const getMultipleError = (c, text) =>
diff --git a/src/queries/title.js b/src/queries/title.ts
similarity index 86%
rename from src/queries/title.js
rename to src/queries/title.ts
index ee304466..f10e740f 100644
--- a/src/queries/title.js
+++ b/src/queries/title.ts
@@ -6,21 +6,23 @@ import {
makeNormalizer,
getNodeText,
buildQueries,
+ Matcher,
+ MatcherOptions,
} from './all-utils'
function queryAllByTitle(
- container,
- text,
- {exact = true, collapseWhitespace, trim, normalizer} = {},
+ container: HTMLElement,
+ text: Matcher,
+ {exact = true, collapseWhitespace, trim, normalizer}: MatcherOptions = {},
) {
checkContainerType(container)
const matcher = exact ? matches : fuzzyMatches
const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer})
return Array.from(container.querySelectorAll('[title], svg > title')).filter(
- node =>
+ (node: HTMLElement) =>
matcher(node.getAttribute('title'), node, text, matchNormalizer) ||
matcher(getNodeText(node), node, text, matchNormalizer),
- )
+ ) as HTMLElement[]
}
const getMultipleError = (c, title) =>
diff --git a/src/query-helpers.js b/src/query-helpers.ts
similarity index 67%
rename from src/query-helpers.js
rename to src/query-helpers.ts
index cd4c3481..8a090385 100644
--- a/src/query-helpers.js
+++ b/src/query-helpers.ts
@@ -1,13 +1,27 @@
import {getSuggestedQuery} from './suggestions'
-import {fuzzyMatches, matches, makeNormalizer} from './matches'
-import {waitFor} from './wait-for'
+import {
+ fuzzyMatches,
+ matches,
+ makeNormalizer,
+ Matcher,
+ MatcherOptions,
+} from './matches'
+import {waitFor, WaitForOptions} from './wait-for'
import {getConfig} from './config'
-function getElementError(message, container) {
+export interface SelectorMatcherOptions extends MatcherOptions {
+ ignore?: string
+ selector?: string
+}
+
+function getElementError(message: string, container: HTMLElement): Error {
return getConfig().getElementError(message, container)
}
-function getMultipleElementsFoundError(message, container) {
+function getMultipleElementsFoundError(
+ message: string,
+ container: HTMLElement,
+): Error {
return getElementError(
`${message}\n\n(If this is intentional, then use the \`*AllBy*\` variant of the query (like \`queryAllByText\`, \`getAllByText\`, or \`findAllByText\`)).`,
container,
@@ -15,20 +29,30 @@ function getMultipleElementsFoundError(message, container) {
}
function queryAllByAttribute(
- attribute,
- container,
- text,
- {exact = true, collapseWhitespace, trim, normalizer} = {},
-) {
+ attribute: string,
+ container: HTMLElement,
+ text: Matcher,
+ {exact = true, collapseWhitespace, trim, normalizer}: MatcherOptions = {},
+): HTMLElement[] {
const matcher = exact ? matches : fuzzyMatches
const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer})
return Array.from(container.querySelectorAll(`[${attribute}]`)).filter(node =>
- matcher(node.getAttribute(attribute), node, text, matchNormalizer),
- )
+ matcher(
+ node.getAttribute(attribute),
+ node as HTMLElement,
+ text,
+ matchNormalizer,
+ ),
+ ) as HTMLElement[]
}
-function queryByAttribute(attribute, container, text, ...args) {
- const els = queryAllByAttribute(attribute, container, text, ...args)
+function queryByAttribute(
+ attribute: string,
+ container: HTMLElement,
+ text: Matcher,
+ options?: MatcherOptions,
+): HTMLElement | null {
+ const els = queryAllByAttribute(attribute, container, text, options)
if (els.length > 1) {
throw getMultipleElementsFoundError(
`Found multiple elements by [${attribute}=${text}]`,
@@ -115,6 +139,7 @@ const wrapAllByQueryWithSuggestion = (query, queryAllByName, variant) => (
// get a unique list of all suggestion messages. We are only going to make a suggestion if
// all the suggestions are the same
const uniqueSuggestionMessages = [
+ // @ts-ignore FIXME with the right tsconfig settings
...new Set(
els.map(element => getSuggestedQuery(element, variant)?.toString()),
),
@@ -132,7 +157,43 @@ const wrapAllByQueryWithSuggestion = (query, queryAllByName, variant) => (
return els
}
-function buildQueries(queryAllBy, getMultipleError, getMissingError) {
+/**
+ * query methods have a common call signature. Only the return type differs.
+ */
+export type QueryMethod
= (
+ container: HTMLElement,
+ ...args: Arguments
+) => Return
+export type QueryBy = QueryMethod<
+ Arguments,
+ HTMLElement | null
+>
+export type GetAllBy = QueryMethod<
+ Arguments,
+ HTMLElement[]
+>
+export type FindAllBy = QueryMethod<
+ [Arguments[0], Arguments[1], WaitForOptions],
+ Promise
+>
+export type GetBy = QueryMethod
+export type FindBy = QueryMethod<
+ [Arguments[0], Arguments[1], WaitForOptions],
+ Promise
+>
+export type BuiltQueryMethods = [
+ QueryBy,
+ GetAllBy,
+ GetBy,
+ FindAllBy,
+ FindBy,
+]
+
+function buildQueries(
+ queryAllBy: GetAllBy,
+ getMultipleError: (container: HTMLElement, ...args: Arguments) => string,
+ getMissingError: (container: HTMLElement, ...args: Arguments) => string,
+): BuiltQueryMethods {
const queryBy = wrapSingleQueryWithSuggestion(
makeSingleQuery(queryAllBy, getMultipleError),
queryAllBy.name,
diff --git a/src/role-helpers.js b/src/role-helpers.ts
similarity index 89%
rename from src/role-helpers.js
rename to src/role-helpers.ts
index f42e3e14..4992a21a 100644
--- a/src/role-helpers.js
+++ b/src/role-helpers.ts
@@ -8,7 +8,7 @@ const elementRoleList = buildElementRoleList(elementRoles)
* @param {Element} element -
* @returns {boolean} - `true` if `element` and its subtree are inaccessible
*/
-function isSubtreeInaccessible(element) {
+function isSubtreeInaccessible(element: HTMLElement): boolean {
if (element.hidden === true) {
return true
}
@@ -25,6 +25,9 @@ function isSubtreeInaccessible(element) {
return false
}
+interface IsInaccessibleOptions {
+ isSubtreeInaccessible?: typeof isSubtreeInaccessible
+}
/**
* Partial implementation https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion
* which should only be used for elements with a non-presentational role i.e.
@@ -39,7 +42,10 @@ function isSubtreeInaccessible(element) {
* can be used to return cached results from previous isSubtreeInaccessible calls
* @returns {boolean} true if excluded, otherwise false
*/
-function isInaccessible(element, options = {}) {
+function isInaccessible(
+ element: HTMLElement,
+ options: IsInaccessibleOptions = {},
+): boolean {
const {
isSubtreeInaccessible: isSubtreeInaccessibleImpl = isSubtreeInaccessible,
} = options
@@ -118,8 +124,8 @@ function buildElementRoleList(elementRolesMap) {
return result.sort(bySelectorSpecificity)
}
-function getRoles(container, {hidden = false} = {}) {
- function flattenDOM(node) {
+function getRoles(container, {hidden = false} = {}): Record {
+ function flattenDOM(node: ParentNode) {
return [
node,
...Array.from(node.children).reduce(
@@ -133,8 +139,8 @@ function getRoles(container, {hidden = false} = {}) {
.filter(element => {
return hidden === false ? isInaccessible(element) === false : true
})
- .reduce((acc, node) => {
- let roles = []
+ .reduce((acc, node: Element) => {
+ let roles: Array = []
// TODO: This violates html-aria which does not allow any role on every element
if (node.hasAttribute('role')) {
roles = node.getAttribute('role').split(' ').slice(0, 1)
@@ -152,7 +158,7 @@ function getRoles(container, {hidden = false} = {}) {
}, {})
}
-function prettyRoles(dom, {hidden}) {
+function prettyRoles(dom: HTMLElement, {hidden}) {
const roles = getRoles(dom, {hidden})
return Object.entries(roles)
@@ -161,7 +167,7 @@ function prettyRoles(dom, {hidden}) {
const elementsString = elements
.map(el => {
const nameString = `Name "${computeAccessibleName(el)}":\n`
- const domString = prettyDOM(el.cloneNode(false))
+ const domString = prettyDOM(el.cloneNode(false) as Element)
return `${nameString}${domString}`
})
.join('\n\n')
@@ -171,7 +177,7 @@ function prettyRoles(dom, {hidden}) {
.join('\n')
}
-const logRoles = (dom, {hidden = false} = {}) =>
+const logRoles = (dom: HTMLElement, {hidden = false} = {}) =>
console.log(prettyRoles(dom, {hidden}))
/**
diff --git a/src/screen.js b/src/screen.ts
similarity index 100%
rename from src/screen.js
rename to src/screen.ts
diff --git a/src/suggestions.js b/src/suggestions.ts
similarity index 69%
rename from src/suggestions.js
rename to src/suggestions.ts
index ff960d68..88e7098b 100644
--- a/src/suggestions.js
+++ b/src/suggestions.ts
@@ -6,10 +6,19 @@ import {getImplicitAriaRoles} from './role-helpers'
const normalize = getDefaultNormalizer()
-function getLabelTextFor(element) {
- let label =
- element.labels &&
- Array.from(element.labels).find(el => Boolean(normalize(el.textContent)))
+function isElementWithLabels(
+ element: HTMLElement,
+): element is HTMLInputElement {
+ // We cast with HTMLInputElement, but it could be a HTMLSelectElement
+ return (element as HTMLInputElement).labels !== undefined
+}
+
+function getLabelTextFor(element: HTMLElement): string | undefined {
+ let label: HTMLLabelElement | undefined =
+ isElementWithLabels(element) &&
+ Array.from(element.labels).find((el: HTMLLabelElement) =>
+ Boolean(normalize(el.textContent)),
+ )
// non form elements that are using aria-labelledby won't be included in `element.labels`
if (!label) {
@@ -30,7 +39,16 @@ function escapeRegExp(string) {
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
}
-function makeSuggestion(queryName, content, {variant = 'get', name}) {
+interface MakeSuggestionOptions {
+ variant?: string
+ name?: string
+}
+
+function makeSuggestion(
+ queryName,
+ content,
+ {variant = 'get', name}: MakeSuggestionOptions,
+) {
const queryArgs = [content]
if (name) {
@@ -55,7 +73,20 @@ function makeSuggestion(queryName, content, {variant = 'get', name}) {
}
}
-export function getSuggestedQuery(element, variant) {
+function isElementWithValue(element: HTMLElement): element is HTMLInputElement {
+ // We cast with HTMLInputElement, but it could be a HTMLSelectElement
+ return Boolean((element as HTMLInputElement).value)
+}
+
+export interface Suggestion {
+ queryName: string
+ toString(): string
+}
+
+export function getSuggestedQuery(
+ element: HTMLElement,
+ variant?: string,
+): Suggestion | undefined {
const role =
element.getAttribute('role') ?? getImplicitAriaRoles(element)?.[0]
if (role) {
@@ -80,7 +111,7 @@ export function getSuggestedQuery(element, variant) {
return makeSuggestion('Text', textContent, {variant})
}
- if (element.value) {
+ if (isElementWithValue(element)) {
return makeSuggestion('DisplayValue', normalize(element.value), {variant})
}
diff --git a/src/wait-for-dom-change.js b/src/wait-for-dom-change.ts
similarity index 85%
rename from src/wait-for-dom-change.js
rename to src/wait-for-dom-change.ts
index 1344db9d..97076388 100644
--- a/src/wait-for-dom-change.js
+++ b/src/wait-for-dom-change.ts
@@ -7,6 +7,7 @@ import {
runWithRealTimers,
} from './helpers'
import {getConfig} from './config'
+import {WaitForOptions} from './wait-for'
let hasWarned = false
@@ -22,7 +23,7 @@ function waitForDomChange({
attributes: true,
characterData: true,
},
-} = {}) {
+}: WaitForOptions = {}) {
if (!hasWarned) {
hasWarned = true
console.warn(
@@ -31,7 +32,9 @@ function waitForDomChange({
}
return new Promise((resolve, reject) => {
const timer = setTimeout(onTimeout, timeout)
- const {MutationObserver} = getWindowFromNode(container)
+ const {MutationObserver} = getWindowFromNode(container) as Window & {
+ MutationObserver: (callback: MutationCallback) => void
+ }
const observer = new MutationObserver(onMutation)
runWithRealTimers(() =>
observer.observe(container, mutationObserverOptions),
@@ -47,7 +50,7 @@ function waitForDomChange({
}
}
- function onMutation(mutationsList) {
+ function onMutation(mutationsList: MutationRecord[]) {
onDone(null, mutationsList)
}
diff --git a/src/wait-for-element-to-be-removed.js b/src/wait-for-element-to-be-removed.ts
similarity index 75%
rename from src/wait-for-element-to-be-removed.js
rename to src/wait-for-element-to-be-removed.ts
index 0703b575..4a2a38b8 100644
--- a/src/wait-for-element-to-be-removed.js
+++ b/src/wait-for-element-to-be-removed.ts
@@ -1,4 +1,4 @@
-import {waitFor} from './wait-for'
+import {waitFor, WaitForOptions} from './wait-for'
const isRemoved = result => !result || (Array.isArray(result) && !result.length)
@@ -12,26 +12,32 @@ function initialCheck(elements) {
}
}
-async function waitForElementToBeRemoved(callback, options) {
+async function waitForElementToBeRemoved(
+ callback: (() => T | T[]) | T | T[],
+ options?: WaitForOptions,
+) {
// created here so we get a nice stacktrace
const timeoutError = new Error('Timed out in waitForElementToBeRemoved.')
+ let cb
if (typeof callback !== 'function') {
initialCheck(callback)
- const elements = Array.isArray(callback) ? callback : [callback]
+ const elements: Array = Array.isArray(callback) ? callback : [callback]
const getRemainingElements = elements.map(element => {
let parent = element.parentElement
while (parent.parentElement) parent = parent.parentElement
return () => (parent.contains(element) ? element : null)
})
- callback = () => getRemainingElements.map(c => c()).filter(Boolean)
+ cb = () => getRemainingElements.map(c => c()).filter(Boolean)
+ } else {
+ cb = callback
}
- initialCheck(callback())
+ initialCheck(cb())
return waitFor(() => {
let result
try {
- result = callback()
+ result = cb()
} catch (error) {
if (error.name === 'TestingLibraryElementError') {
return true
diff --git a/src/wait-for-element.js b/src/wait-for-element.ts
similarity index 82%
rename from src/wait-for-element.js
rename to src/wait-for-element.ts
index 060f17be..8bc585d9 100644
--- a/src/wait-for-element.js
+++ b/src/wait-for-element.ts
@@ -1,11 +1,14 @@
-import {waitFor} from './wait-for'
+import {waitFor, WaitForOptions} from './wait-for'
let hasWarned = false
// deprecated... TODO: remove this method. People should use a find* query or
// wait instead the reasoning is that this doesn't really do anything useful
// that you can't get from using find* or wait.
-async function waitForElement(callback, options) {
+async function waitForElement(
+ callback: () => T extends Promise ? never : T,
+ options?: WaitForOptions,
+): Promise {
if (!hasWarned) {
hasWarned = true
console.warn(
diff --git a/src/wait-for.js b/src/wait-for.ts
similarity index 80%
rename from src/wait-for.js
rename to src/wait-for.ts
index b271a00d..c77a54c2 100644
--- a/src/wait-for.js
+++ b/src/wait-for.ts
@@ -17,7 +17,7 @@ function copyStackTrace(target, source) {
function waitFor(
callback,
{
- container = getDocument(),
+ container = getDocument() as Node,
timeout = getConfig().asyncUtilTimeout,
showOriginalStackTrace = getConfig().showOriginalStackTrace,
stackTraceError,
@@ -27,7 +27,7 @@ function waitFor(
childList: true,
attributes: true,
characterData: true,
- },
+ } as MutationObserverInit,
},
) {
if (typeof callback !== 'function') {
@@ -40,7 +40,9 @@ function waitFor(
const overallTimeoutTimer = setTimeout(onTimeout, timeout)
const intervalId = setInterval(checkCallback, interval)
- const {MutationObserver} = getWindowFromNode(container)
+ const {MutationObserver} = (getWindowFromNode(container) as unknown) as {
+ MutationObserver: (callback: MutationCallback) => void
+ }
const observer = new MutationObserver(checkCallback)
runWithRealTimers(() =>
observer.observe(container, mutationObserverOptions),
@@ -90,7 +92,18 @@ function waitFor(
})
}
-function waitForWrapper(callback, options) {
+export interface WaitForOptions {
+ container?: Node
+ timeout?: number
+ interval?: number
+ mutationObserverOptions?: MutationObserverInit
+ showOriginalStackTrace?: boolean
+}
+
+function waitForWrapper(
+ callback: () => T extends Promise ? never : T,
+ options?: WaitForOptions,
+): Promise {
// create the error here so its stack trace is as close to the
// calling code as possible
const stackTraceError = new Error('STACK_TRACE_MESSAGE')
@@ -103,16 +116,21 @@ let hasWarned = false
// deprecated... TODO: remove this method. We renamed this to `waitFor` so the
// code people write reads more clearly.
-function wait(...args) {
+interface WaitOptions {
+ container?: Node
+ timeout?: number
+ interval?: number
+ mutationObserverOptions?: MutationObserverInit
+}
+function wait(first: () => void, options?: WaitOptions): Promise {
// istanbul ignore next
- const [first = () => {}, ...rest] = args
if (!hasWarned) {
hasWarned = true
console.warn(
`\`wait\` has been deprecated and replaced by \`waitFor\` instead. In most cases you should be able to find/replace \`wait\` with \`waitFor\`. Learn more: https://testing-library.com/docs/dom-testing-library/api-async#waitfor.`,
)
}
- return waitForWrapper(first, ...rest)
+ return waitForWrapper(first, options)
}
export {waitForWrapper as waitFor, wait}
diff --git a/tsconfig.build.json b/tsconfig.build.json
new file mode 100644
index 00000000..3325a603
--- /dev/null
+++ b/tsconfig.build.json
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "noEmit": false,
+ "emitDeclarationOnly": true
+ }
+}
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 00000000..406ef8e6
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "compilerOptions": {
+ "outDir": "./types/",
+ "allowJs": true,
+ "declaration": true,
+ "noEmit": true,
+ "allowSyntheticDefaultImports": true
+ },
+ "include": ["./src/**/*.ts"]
+}
diff --git a/types/config.d.ts b/types/config.d.ts
deleted file mode 100644
index a1fa9fe1..00000000
--- a/types/config.d.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-export interface Config {
- testIdAttribute: string;
- asyncWrapper(cb: (...args: any[]) => any): Promise;
- eventWrapper(cb: (...args: any[]) => any): void;
- asyncUtilTimeout: number;
- defaultHidden: boolean;
- throwSuggestions: boolean;
-}
-
-export interface ConfigFn {
- (existingConfig: Config): Partial;
-}
-
-export function configure(configDelta: Partial | ConfigFn): void;
diff --git a/types/events.d.ts b/types/events.d.ts
deleted file mode 100644
index d9c50cb7..00000000
--- a/types/events.d.ts
+++ /dev/null
@@ -1,95 +0,0 @@
-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;
diff --git a/types/get-node-text.d.ts b/types/get-node-text.d.ts
deleted file mode 100644
index 5c5654b5..00000000
--- a/types/get-node-text.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-export function getNodeText(node: HTMLElement): string;
diff --git a/types/get-queries-for-element.d.ts b/types/get-queries-for-element.d.ts
deleted file mode 100644
index b93adfe1..00000000
--- a/types/get-queries-for-element.d.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import * as queries from './queries';
-
-export type BoundFunction = 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 = { [P in keyof T]: BoundFunction };
-
-export type Query = (
- container: HTMLElement,
- ...args: any[]
-) => Error | Promise | Promise | HTMLElement[] | HTMLElement | null;
-
-export interface Queries {
- [T: string]: Query;
-}
-
-export function getQueriesForElement(
- element: HTMLElement,
- queriesToBind?: T,
-): BoundFunctions;
diff --git a/types/index.d.ts b/types/index.d.ts
deleted file mode 100644
index 5b199dcf..00000000
--- a/types/index.d.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-// TypeScript Version: 3.8
-
-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';
-export * from './suggestions';
diff --git a/types/matches.d.ts b/types/matches.d.ts
deleted file mode 100644
index 6454c86a..00000000
--- a/types/matches.d.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-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
- /** suppress suggestions for a specific query */
- suggest?: boolean
-}
-
-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
diff --git a/types/pretty-dom.d.ts b/types/pretty-dom.d.ts
deleted file mode 100644
index bca6afb4..00000000
--- a/types/pretty-dom.d.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-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;
diff --git a/types/queries.d.ts b/types/queries.d.ts
deleted file mode 100644
index 92c1b946..00000000
--- a/types/queries.d.ts
+++ /dev/null
@@ -1,139 +0,0 @@
-import { Matcher, MatcherOptions } from './matches';
-import { SelectorMatcherOptions } from './query-helpers';
-import { waitForOptions } from './wait-for';
-
-export type QueryByBoundAttribute = (
- container: HTMLElement,
- id: Matcher,
- options?: MatcherOptions,
-) => HTMLElement | null;
-
-export type AllByBoundAttribute = (container: HTMLElement, id: Matcher, options?: MatcherOptions) => HTMLElement[];
-
-export type FindAllByBoundAttribute = (
- container: HTMLElement,
- id: Matcher,
- options?: MatcherOptions,
- waitForElementOptions?: waitForOptions,
-) => Promise;
-
-export type GetByBoundAttribute = (container: HTMLElement, id: Matcher, options?: MatcherOptions) => HTMLElement;
-
-export type FindByBoundAttribute = (
- container: HTMLElement,
- id: Matcher,
- options?: MatcherOptions,
- waitForElementOptions?: waitForOptions,
-) => Promise;
-
-export type QueryByText = (container: HTMLElement, id: Matcher, options?: SelectorMatcherOptions) => HTMLElement | null;
-
-export type AllByText = (container: HTMLElement, id: Matcher, options?: SelectorMatcherOptions) => HTMLElement[];
-
-export type FindAllByText = (
- container: HTMLElement,
- id: Matcher,
- options?: SelectorMatcherOptions,
- waitForElementOptions?: waitForOptions,
-) => Promise;
-
-export type GetByText = (container: HTMLElement, id: Matcher, options?: SelectorMatcherOptions) => HTMLElement;
-
-export type FindByText = (
- container: HTMLElement,
- id: Matcher,
- options?: SelectorMatcherOptions,
- waitForElementOptions?: waitForOptions,
-) => Promise;
-
-export interface ByRoleOptions extends MatcherOptions {
- /**
- * If true includes elements in the query set that are usually excluded from
- * the accessibility tree. `role="none"` or `role="presentation"` are included
- * in either case.
- */
- hidden?: boolean;
- /**
- * If true only includes elements in the query set that are marked as
- * selected in the accessibility tree, i.e., `aria-selected="true"`
- */
- selected?: boolean;
- /**
- * Includes every role used in the `role` attribute
- * For example *ByRole('progressbar', {queryFallbacks: true})` will find `.
- */
- queryFallbacks?: boolean;
- /**
- * Only considers elements with the specified accessible name.
- */
- name?: string | RegExp | ((accessibleName: string, element: Element) => boolean);
-}
-
-export type AllByRole = (container: HTMLElement, role: Matcher, options?: ByRoleOptions) => HTMLElement[];
-
-export type GetByRole = (container: HTMLElement, role: Matcher, options?: ByRoleOptions) => HTMLElement;
-
-export type QueryByRole = (container: HTMLElement, role: Matcher, options?: ByRoleOptions) => HTMLElement | null;
-
-export type FindByRole = (
- container: HTMLElement,
- role: Matcher,
- options?: ByRoleOptions,
- waitForElementOptions?: waitForOptions,
-) => Promise
;
-
-export type FindAllByRole = (
- container: HTMLElement,
- role: Matcher,
- options?: ByRoleOptions,
- waitForElementOptions?: waitForOptions,
-) => Promise;
-
-export const getByLabelText: GetByText;
-export const getAllByLabelText: AllByText;
-export const queryByLabelText: QueryByText;
-export const queryAllByLabelText: AllByText;
-export const findByLabelText: FindByText;
-export const findAllByLabelText: FindAllByText;
-export const getByPlaceholderText: GetByBoundAttribute;
-export const getAllByPlaceholderText: AllByBoundAttribute;
-export const queryByPlaceholderText: QueryByBoundAttribute;
-export const queryAllByPlaceholderText: AllByBoundAttribute;
-export const findByPlaceholderText: FindByBoundAttribute;
-export const findAllByPlaceholderText: FindAllByBoundAttribute;
-export const getByText: GetByText;
-export const getAllByText: AllByText;
-export const queryByText: QueryByText;
-export const queryAllByText: AllByText;
-export const findByText: FindByText;
-export const findAllByText: FindAllByText;
-export const getByAltText: GetByBoundAttribute;
-export const getAllByAltText: AllByBoundAttribute;
-export const queryByAltText: QueryByBoundAttribute;
-export const queryAllByAltText: AllByBoundAttribute;
-export const findByAltText: FindByBoundAttribute;
-export const findAllByAltText: FindAllByBoundAttribute;
-export const getByTitle: GetByBoundAttribute;
-export const getAllByTitle: AllByBoundAttribute;
-export const queryByTitle: QueryByBoundAttribute;
-export const queryAllByTitle: AllByBoundAttribute;
-export const findByTitle: FindByBoundAttribute;
-export const findAllByTitle: FindAllByBoundAttribute;
-export const getByDisplayValue: GetByBoundAttribute;
-export const getAllByDisplayValue: AllByBoundAttribute;
-export const queryByDisplayValue: QueryByBoundAttribute;
-export const queryAllByDisplayValue: AllByBoundAttribute;
-export const findByDisplayValue: FindByBoundAttribute;
-export const findAllByDisplayValue: FindAllByBoundAttribute;
-export const getByRole: GetByRole;
-export const getAllByRole: AllByRole;
-export const queryByRole: QueryByRole;
-export const queryAllByRole: AllByRole;
-export const findByRole: FindByRole;
-export const findAllByRole: FindAllByRole;
-export const getByTestId: GetByBoundAttribute;
-export const getAllByTestId: AllByBoundAttribute;
-export const queryByTestId: QueryByBoundAttribute;
-export const queryAllByTestId: AllByBoundAttribute;
-export const findByTestId: FindByBoundAttribute;
-export const findAllByTestId: FindAllByBoundAttribute;
diff --git a/types/query-helpers.d.ts b/types/query-helpers.d.ts
deleted file mode 100644
index de50a2d3..00000000
--- a/types/query-helpers.d.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { Matcher, MatcherOptions } from './matches'
-import { waitForOptions } from './wait-for'
-
-export interface SelectorMatcherOptions extends MatcherOptions {
- selector?: string
-}
-
-export type QueryByAttribute = (
- attribute: string,
- container: HTMLElement,
- id: Matcher,
- options?: MatcherOptions,
-) => HTMLElement | null
-
-export type AllByAttribute = (
- attribute: string,
- container: HTMLElement,
- id: Matcher,
- options?: MatcherOptions,
-) => HTMLElement[]
-
-export const queryByAttribute: QueryByAttribute
-export const queryAllByAttribute: AllByAttribute
-export function getElementError(message: string, container: HTMLElement): Error
-
-/**
- * query methods have a common call signature. Only the return type differs.
- */
-export type QueryMethod = (
- container: HTMLElement,
- ...args: Arguments
-) => Return
-export type QueryBy = QueryMethod<
- Arguments,
- HTMLElement | null
->
-export type GetAllBy = QueryMethod<
- Arguments,
- HTMLElement[]
->
-export type FindAllBy = QueryMethod<
- [Arguments[0], Arguments[1], waitForOptions],
- Promise
->
-export type GetBy = QueryMethod
-export type FindBy = QueryMethod<
- [Arguments[0], Arguments[1], waitForOptions],
- Promise
->
-
-export type BuiltQueryMethods = [
- QueryBy,
- GetAllBy,
- GetBy,
- FindAllBy,
- FindBy,
-]
-export function buildQueries(
- queryByAll: GetAllBy,
- getMultipleError: (container: HTMLElement, ...args: Arguments) => string,
- getMissingError: (container: HTMLElement, ...args: Arguments) => string,
-): BuiltQueryMethods
diff --git a/types/role-helpers.d.ts b/types/role-helpers.d.ts
deleted file mode 100644
index 3dd35b78..00000000
--- a/types/role-helpers.d.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export function logRoles(container: HTMLElement): string;
-export function getRoles(container: HTMLElement): { [index: string]: HTMLElement[] };
-/**
- * https://testing-library.com/docs/dom-testing-library/api-helpers#isinaccessible
- */
-export function isInaccessible(element: Element): boolean;
diff --git a/types/screen.d.ts b/types/screen.d.ts
deleted file mode 100644
index 2594f5be..00000000
--- a/types/screen.d.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { BoundFunctions, Queries } from './get-queries-for-element';
-import * as queries from './queries';
-import { OptionsReceived } from 'pretty-format';
-
-export type Screen = BoundFunctions & {
- /**
- * Convenience function for `pretty-dom` which also allows an array
- * of elements
- */
- debug: (
- element?: Element | HTMLDocument | Array,
- maxLength?: number,
- options?: OptionsReceived,
- ) => void;
-};
-
-export const screen: Screen;
diff --git a/types/suggestions.d.ts b/types/suggestions.d.ts
deleted file mode 100644
index f574f344..00000000
--- a/types/suggestions.d.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export interface Suggestion {
- queryName: string
- toString(): string
-}
-
-export function getSuggestedQuery(element: HTMLElement): Suggestion | undefined
diff --git a/types/tslint.json b/types/tslint.json
index 5d45232f..a439c551 100644
--- a/types/tslint.json
+++ b/types/tslint.json
@@ -1,8 +1,14 @@
{
"extends": ["dtslint/dtslint.json"],
"rules": {
+ "one-variable-per-declaration": false,
+ "max-line-length": false,
+ "no-redundant-jsdoc": false,
"no-useless-files": false,
"no-relative-import-in-test": false,
- "semicolon": false
+ "prefer-declare-function": false,
+ "semicolon": false,
+ "strict-export-declare-modifiers": false,
+ "whitespace": false
}
}
diff --git a/types/wait-for-dom-change.d.ts b/types/wait-for-dom-change.d.ts
deleted file mode 100644
index 813437f4..00000000
--- a/types/wait-for-dom-change.d.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import { waitForOptions } from "./wait-for";
-
-export function waitForDomChange(options?: waitForOptions): Promise;
diff --git a/types/wait-for-element-to-be-removed.d.ts b/types/wait-for-element-to-be-removed.d.ts
deleted file mode 100644
index b6b1e1bb..00000000
--- a/types/wait-for-element-to-be-removed.d.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import { waitForOptions } from "./wait-for";
-
-export function waitForElementToBeRemoved(
- callback: (() => T) | T,
- options?: waitForOptions,
-): Promise;
diff --git a/types/wait-for-element.d.ts b/types/wait-for-element.d.ts
deleted file mode 100644
index 4fe1de0e..00000000
--- a/types/wait-for-element.d.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import { waitForOptions } from "./wait-for";
-
-export function waitForElement(callback: () => T, options?: waitForOptions): Promise;
diff --git a/types/wait-for.d.ts b/types/wait-for.d.ts
deleted file mode 100644
index 0fd0e56a..00000000
--- a/types/wait-for.d.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export interface waitForOptions {
- container?: HTMLElement
- timeout?: number
- interval?: number
- mutationObserverOptions?: MutationObserverInit
-}
-
-export function waitFor(
- callback: () => T extends Promise ? never : T,
- options?: waitForOptions,
-): Promise
diff --git a/types/wait.d.ts b/types/wait.d.ts
deleted file mode 100644
index 3763e7bd..00000000
--- a/types/wait.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-export function wait(
- callback?: () => void,
- options?: {
- timeout?: number;
- interval?: number;
- },
-): Promise;