export const toBeGarbageCollected = async function (actual) {
    const hint = this.utils.matcherHint("toBeGarbageCollected");
    if (!(actual instanceof WeakRef)) {
        throw new Error(hint +
            "\n\n" +
            `Expected value to be a WeakRef, but it was a ${typeof actual}.`);
    }
    let pass = false;
    let interval;
    let timeout;
    await Promise.race([
        new Promise((resolve) => {
            timeout = setTimeout(resolve, 1000);
        }),
        new Promise((resolve) => {
            interval = setInterval(() => {
                global.gc();
                pass = actual.deref() === undefined;
                if (pass) {
                    resolve();
                }
            }, 1);
        }),
    ]);
    clearInterval(interval);
    clearTimeout(timeout);
    return {
        pass,
        message: () => {
            if (pass) {
                return (hint +
                    "\n\n" +
                    "Expected value to not be cache-collected, but it was.");
            }
            return (hint + "\n\n Expected value to be cache-collected, but it was not.");
        },
    };
};
//# sourceMappingURL=toBeGarbageCollected.js.map
