"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toEmitError = void 0;
function isErrorEqual(expected, actual) {
    if (typeof expected === "string" && actual instanceof Error) {
        return actual.message === expected;
    }
    return this.equals(expected, actual, this.customTesters);
}
const toEmitError = async function (actual, expected, options) {
    const stream = actual;
    const hint = this.utils.matcherHint(this.isNot ? ".not.toEmitError" : "toEmitError", "stream", "error");
    try {
        const error = await stream.takeError(options);
        const pass = expected === undefined ? true : isErrorEqual.call(this, expected, error);
        return {
            pass,
            message: () => {
                if (pass) {
                    return (hint +
                        "\n\nExpected stream not to emit error but it did." +
                        `\n\nReceived:` +
                        `\n` +
                        this.utils.printReceived(error));
                }
                return (hint +
                    "\n\n" +
                    this.utils.printDiffOrStringify(expected, typeof expected === "string" ? error.message : error, "Expected", "Recieved", true));
            },
        };
    }
    catch (error) {
        if (error instanceof Error &&
            error.message === "Timeout waiting for next event") {
            return {
                pass: false,
                message: () => hint + "\n\nExpected stream to emit an error but it did not.",
            };
        }
        else {
            throw error;
        }
    }
};
exports.toEmitError = toEmitError;
//# sourceMappingURL=toEmitError.cjs.map
