"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Waits for callback to not throw. Similar to react-native-testing-library's waitFor, but works better
// with Joplin's mix of real and fake Jest timers.
const realSetTimeout = setTimeout;
const waitFor = async (callback) => {
    const timeout = 10000;
    const startTime = performance.now();
    let passed = false;
    let lastError = null;
    while (!passed && performance.now() - startTime < timeout) {
        try {
            await callback();
            passed = true;
            lastError = null;
        }
        catch (error) {
            lastError = error;
            await new Promise(resolve => {
                realSetTimeout(() => resolve(), 10);
            });
        }
    }
    if (lastError) {
        throw lastError;
    }
};
exports.default = waitFor;
//# sourceMappingURL=waitFor.js.map