I am in the process of implementing a custom matcher for Playwright based on the information provided in the official documentation on extending expect
. In a similar vein to this unanswered discussion, my goal is to invoke an existing matcher after modifying the input:
expect.extend({
async toHaveDeploymentURL(page: Page, expected: string) {
const fullyQualifiedPath = `https://deployments.company.com${expected}`;
// The issue lies here; trying to call an existing matcher
return expect(page).toHaveURL(fullyQualifiedPath);
},
});
While browsing through a discussion on Jest issues, I came across a workaround to directly incorporate the Jest matchers:
import { getMatchers } from "expect/build/jestMatchersObject";
return expect.extend({
toMatchEntity(actual, expected) {
const copy = ... // object manipulation
return getMatchers().toMatchObject.call(this, copy, expected);
},
});
However, replicating this approach with Playwright matchers seems unfeasible as they are not exported in the package.json for @playwright/test.
Is there a different method to accomplish this task?