import {eventually} from '@wix/unidriver-core/internal'; function getGlobalThis() { if (typeof globalThis !== 'undefined') { return globalThis; } if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } // @ts-expect-error types issues if (typeof global !== 'undefined') { // @ts-expect-error types issues // eslint-disable-next-line @typescript-eslint/no-unsafe-return return global; } throw new Error('unable to locate global object'); } function setIsReactActEnvironment(isReactActEnvironment: boolean) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; } function getIsReactActEnvironment() { // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; } // This is a very simplified copy of what testing-library/react is doing export const waitForLegacy = async ( fn: () => Promise, params?: { message?: string; timeout?: number; }, ) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const previousActEnvironment = getIsReactActEnvironment(); setIsReactActEnvironment(false); try { await eventually(async () => { const result = await fn(); if (!result) { throw new Error('predicate returned false'); } }, params); } finally { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument setIsReactActEnvironment(previousActEnvironment); } };