Skip to content

Commit

Permalink
fix: adjust normalization for regex values in matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
pengooseDev committed Nov 11, 2024
1 parent d98fc8b commit d3484a5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/playwright/src/matchers/toEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ export async function toEqual<T>(
if (pass) {
printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;
printedReceived = `Received: ${this.utils.printReceived(received)}`;
} else if (Array.isArray(expected) && Array.isArray(received)) {
const normalizedExpected = expected.map((exp, index) => {
const rec = received[index];
if (exp instanceof RegExp)
return exp.test(rec) ? rec : exp;

return exp;
});
printedDiff = this.utils.printDiffOrStringify(
normalizedExpected,
received,
EXPECTED_LABEL,
RECEIVED_LABEL,
false,
);
} else {
printedDiff = this.utils.printDiffOrStringify(
expected,
Expand Down

0 comments on commit d3484a5

Please sign in to comment.