diff --git a/types/testing-library__dom/index.d.ts b/types/testing-library__dom/index.d.ts index e70946b94a..d6747b4871 100644 --- a/types/testing-library__dom/index.d.ts +++ b/types/testing-library__dom/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for @testing-library/dom 6.14 +// Type definitions for @testing-library/dom 7.0 // Project: https://github.com/testing-library/dom-testing-library // Definitions by: Alex Krolick // Kent C Dodds @@ -21,6 +21,7 @@ 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'; diff --git a/types/testing-library__dom/package.json b/types/testing-library__dom/package.json index 9962e110c0..a019c58ee7 100644 --- a/types/testing-library__dom/package.json +++ b/types/testing-library__dom/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "pretty-format": "^24.3.0" + "pretty-format": "^25.1.0" } } diff --git a/types/testing-library__dom/testing-library__dom-tests.ts b/types/testing-library__dom/testing-library__dom-tests.ts index 10b7bd25ef..a7d7d6c518 100644 --- a/types/testing-library__dom/testing-library__dom-tests.ts +++ b/types/testing-library__dom/testing-library__dom-tests.ts @@ -1,4 +1,4 @@ -import { fireEvent, queries, screen, isInaccessible } from '@testing-library/dom'; +import { fireEvent, isInaccessible, queries, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/dom'; const { getByText, queryByText, findByText, getAllByText, queryAllByText, findAllByText, queryAllByRole, queryByRole, findByRole } = queries; @@ -73,3 +73,20 @@ function eventTest() { } 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 = 'apple'; + + await waitForElementToBeRemoved(() => getByText(element, 'apple')); + await waitForElementToBeRemoved(getByText(element, 'apple')); + await waitForElementToBeRemoved(getAllByText(element, 'apple')); +} diff --git a/types/testing-library__dom/wait-for-element-to-be-removed.d.ts b/types/testing-library__dom/wait-for-element-to-be-removed.d.ts index 5cd4ef00ec..567bce8fc8 100644 --- a/types/testing-library__dom/wait-for-element-to-be-removed.d.ts +++ b/types/testing-library__dom/wait-for-element-to-be-removed.d.ts @@ -1,5 +1,5 @@ export function waitForElementToBeRemoved( - callback: () => T, + callback: (() => T) | T, options?: { container?: HTMLElement; timeout?: number; diff --git a/types/testing-library__dom/wait-for.d.ts b/types/testing-library__dom/wait-for.d.ts new file mode 100644 index 0000000000..0c68bf2461 --- /dev/null +++ b/types/testing-library__dom/wait-for.d.ts @@ -0,0 +1,9 @@ +export function waitFor( + callback: () => T, + options?: { + container?: HTMLElement; + timeout?: number; + interval?: number; + mutationObserverOptions?: MutationObserverInit; + }, +): Promise;