diff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.ts index 8a8089e91e20f..acf4c5bcc89af 100644 --- a/packages/playwright/src/matchers/matchers.ts +++ b/packages/playwright/src/matchers/matchers.ts @@ -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); } diff --git a/packages/playwright/src/matchers/toMatchText.ts b/packages/playwright/src/matchers/toMatchText.ts index 2f8bc34b21398..73c7011cb6117 100644 --- a/packages/playwright/src/matchers/toMatchText.ts +++ b/packages/playwright/src/matchers/toMatchText.ts @@ -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 = () => {