diff --git a/src/__tests__/wait-for-element.js b/src/__tests__/wait-for-element.js deleted file mode 100644 index e766b47a..00000000 --- a/src/__tests__/wait-for-element.js +++ /dev/null @@ -1,60 +0,0 @@ -import {waitForElement} from '..' -import {render, renderIntoDocument} from './helpers/test-utils' - -afterEach(() => { - jest.useRealTimers() -}) - -test('waits for element to appear in the document', async () => { - const {rerender, getByTestId} = renderIntoDocument('
') - const promise = waitForElement(() => getByTestId('div')) - setTimeout(() => rerender('
')) - const element = await promise - expect(element).toBeInTheDocument() -}) - -test('can time out', async () => { - await expect(waitForElement(() => {}, {timeout: 1})).rejects.toThrow( - /timed out/i, - ) -}) - -test('waits for element to appear in a specified container', async () => { - const {rerender, container, getByTestId} = render('
') - const promise = waitForElement(() => getByTestId('div'), {container}) - setTimeout(() => rerender('
')) - const element = await promise - expect(element).toBeTruthy() -}) - -test('throws last thrown error', async () => { - const {rerender, container} = render('
') - let error - setTimeout(() => { - error = new Error('first error') - rerender('
first
') - }, 10) - setTimeout(() => { - error = new Error('second error') - rerender('
second
') - }, 20) - const promise = waitForElement( - () => { - throw error - }, - {container, timeout: 50}, - ) - await expect(promise).rejects.toThrow(error) -}) - -test('waits until callback does not return null', async () => { - const {rerender, container, queryByTestId} = render('
') - const promise = waitForElement(() => queryByTestId('div'), {container}) - setTimeout(() => rerender('
')) - const element = await promise - expect(element).toBeTruthy() -}) - -test('throws error if no callback is provided', async () => { - await expect(waitForElement()).rejects.toThrow(/callback/i) -}) diff --git a/src/index.js b/src/index.js index 660d0849..63e1c3ce 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,6 @@ import * as queryHelpers from './query-helpers' export * from './queries' export * from './wait-for' -export * from './wait-for-element' export * from './wait-for-element-to-be-removed' export {getDefaultNormalizer} from './matches' export * from './get-node-text' diff --git a/src/wait-for-element.js b/src/wait-for-element.js deleted file mode 100644 index 060f17be..00000000 --- a/src/wait-for-element.js +++ /dev/null @@ -1,32 +0,0 @@ -import {waitFor} 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) { - if (!hasWarned) { - hasWarned = true - console.warn( - `\`waitForElement\` has been deprecated. Use a \`find*\` query (preferred: https://testing-library.com/docs/dom-testing-library/api-queries#findby) or use \`waitFor\` instead: https://testing-library.com/docs/dom-testing-library/api-async#waitfor`, - ) - } - if (!callback) { - throw new Error('waitForElement requires a callback as the first parameter') - } - return waitFor(() => { - const result = callback() - if (!result) { - throw new Error('Timed out in waitForElement.') - } - return result - }, options) -} - -export {waitForElement} - -/* -eslint - require-await: "off" -*/ diff --git a/types/index.d.ts b/types/index.d.ts index 6aa73594..b5dcfbc2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -11,7 +11,6 @@ export * from './queries' export * from './query-helpers' export * from './screen' export * from './wait-for' -export * from './wait-for-element' export * from './wait-for-element-to-be-removed' export * from './matches' export * from './get-node-text' diff --git a/types/wait-for-element.d.ts b/types/wait-for-element.d.ts deleted file mode 100644 index 29e7e72c..00000000 --- a/types/wait-for-element.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {waitForOptions} from './wait-for' - -/** - * @deprecated `waitForElement` has been deprecated. - * Use a `find*` query (preferred: https://testing-library.com/docs/dom-testing-library/api-queries#findby) - * or use `waitFor` instead: https://testing-library.com/docs/dom-testing-library/api-async#waitfor - */ -export function waitForElement( - callback: () => T, - options?: waitForOptions, -): Promise