Skip to content

[Question] How to pass custom error message to custom matchers in Playwright #22453

Open
@sankarkec

Description

I am creating my own custom matches in playwright. Everything works fine expect custom message. Below is my code

expect.extend({
toEqualIgnoreCase(actual: string, expected: string, messageOrOptions?: string) {
        console.log("actual: " + actual + ", expected: " + expected+ ", Message: " + messageOrOptions);
        if (actual.toUpperCase() == expected.toUpperCase()) {
            return {
                message: () =>  "Expected '" + actual + "' to equal ignore case '" + expected + "', '" + messageOrOptions + "'",
                pass: true,
            };
        } else {
            return {
                message: () =>  "Expected '" + actual + "' to equal ignore case '" + expected + "', '" + messageOrOptions + "'",
                pass: false,
            };
        }
    },
});

In Test i called like

expect("test", "custom message").toEqualIgnoreCase("Test1");

But inside the custom matchers only actual and expected value received but custom message not received. How to pass the message for custom matchers.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions