mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
d6265d9dcb
* chore: bump React Native to 0.64 RC * Snapshot update * Bumped node version to 12 on CI * Removed removed supress_comment syntax from config * codemod types-first * Prettied files after codemod * Added flow types to API returns * don't return null from fireEvent handlers * return ReactTestInstance instead of any * fix render returning any * less anys * less anys * simplify call type * simplify * add Flow to missing files, type debug better Co-authored-by: Michał Parkitny <michal.parkitny@callstack.com> Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
// @flow
|
|
import waitFor, { type WaitForOptions } from './waitFor';
|
|
import { ErrorWithStack } from './helpers/errors';
|
|
|
|
function isRemoved<T>(result: T): boolean {
|
|
return !result || (Array.isArray(result) && !result.length);
|
|
}
|
|
|
|
export default async function waitForElementToBeRemoved<T>(
|
|
expectation: () => T,
|
|
options?: WaitForOptions
|
|
): Promise<T> {
|
|
// Created here so we get a nice stacktrace
|
|
const timeoutError = new ErrorWithStack(
|
|
'Timed out in waitForElementToBeRemoved.',
|
|
waitForElementToBeRemoved
|
|
);
|
|
|
|
// Elements have to be present initally and then removed.
|
|
const initialElements = expectation();
|
|
if (isRemoved(initialElements)) {
|
|
throw new ErrorWithStack(
|
|
'The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.',
|
|
waitForElementToBeRemoved
|
|
);
|
|
}
|
|
|
|
return waitFor(() => {
|
|
let result;
|
|
try {
|
|
result = expectation();
|
|
} catch (error) {
|
|
return initialElements;
|
|
}
|
|
|
|
if (!isRemoved(result)) {
|
|
throw timeoutError;
|
|
}
|
|
|
|
return initialElements;
|
|
}, options);
|
|
}
|