Skip to content

Files

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Latest commit

3808482 · Aug 18, 2022

History

History
41 lines (31 loc) · 1.34 KB

no-wait-for-empty-callback.md

File metadata and controls

41 lines (31 loc) · 1.34 KB

Empty callbacks inside waitFor and waitForElementToBeRemoved are not preferred (testing-library/no-wait-for-empty-callback)

Rule Details

This rule aims to ensure the correct usage of waitFor and waitForElementToBeRemoved, in the way that they're intended to be used. If an empty callback is passed, these methods will just wait next tick of the event loop before proceeding, and that's not consistent with the philosophy of the library. Instead, insert an assertion in that callback function.

Examples of incorrect code for this rule:

const foo = async () => {
	await waitFor(() => {});
	await waitFor(function () {});
	await waitFor(noop);

	await waitForElementToBeRemoved(() => {});
	await waitForElementToBeRemoved(function () {});
	await waitForElementToBeRemoved(noop);
};

Examples of correct code for this rule:

const foo = async () => {
	await waitFor(() => {
		screen.getByText(/submit/i);
	});

	const submit = screen.getByText(/submit/i);
	await waitForElementToBeRemoved(() => submit);
	// or
	await waitForElementToBeRemoved(submit);
};

Further Reading