expect-playwright icon indicating copy to clipboard operation
expect-playwright copied to clipboard

toMatchText failed due to whitespaces

Open yotov opened this issue 4 years ago • 1 comments

Hi guys,

I replaced the deprecated method toHaveText with the new one toMatchText and many of the tests failed. The reason for the failure is the presence of whitespace.

For example, this code is going to fail:

<button>
<i class="click-icon"></i>
<span>Click here</span>
</button>
------------------------
await expect(page).toMatchText('button', 'Click here');

Is there an option to modify toMatchText to run trim on textContent?

yotov avatar Sep 10 '21 12:09 yotov

@yotov toMatchText supports regex for partial string matching. This should work.

await expect(page).toMatchText('button', /Click here/);

mskelton avatar Sep 10 '21 14:09 mskelton