Skip to content

Commit

Permalink
feat: normalize whitespace for values with HTML entities
Browse files Browse the repository at this point in the history
  • Loading branch information
pengooseDev committed Dec 9, 2024
1 parent be27666 commit 59c49b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/playwright/src/matchers/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export function toHaveValue(
options?: { timeout?: number },
) {
return toMatchText.call(this, 'toHaveValue', locator, 'Locator', async (isNot, timeout) => {
const expectedText = serializeExpectedTextValues([expected]);
const expectedText = serializeExpectedTextValues([expected], { normalizeWhiteSpace: true });
return await locator._expect('to.have.value', { expectedText, isNot, timeout });
}, expected, options);
}
Expand Down
18 changes: 18 additions & 0 deletions packages/playwright/src/matchers/toMatchText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ export async function toMatchText(
} else {
printedDiff = this.utils.printDiffOrStringify(expected, receivedString, labelExpected, 'Received string', false);
}
if (typeof expected === 'string' && / /.test(receivedString)) {
const normalizedReceived = receivedString.replace(/ /g, ' ');
if (expected === normalizedReceived) {
return {
name: matcherName,
message: () => '',
pass: true,
expected,
};
}
printedDiff = this.utils.printDiffOrStringify(
expected,
normalizedReceived,
'Expected string:',
'Received string:',
false
);
}
}

const message = () => {
Expand Down

0 comments on commit 59c49b9

Please sign in to comment.