Page(s)
https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-class
Description
The docs mention a 'relaxed regular expression' but doesn't define what 'relaxed' means. The existing example of toHaveClass(/selected/) would also match class="selectedfoo row"
I think it could be helpful if the example used the zero length word boundary pattern, \b:
<div class='selected row' id='component></div>
const locator = page.locator('#component');
await expect(locator).toHaveClass(/\bselected\b/);
await expect(locator).toHaveClass(/\brow\b/);
Unfortunately, \b considers - to be a boundary, so there is still some possible ambiguity. Perhaps /(^|\s)selected(\s|$)/ would be better
<div class='selected row' id='component></div>
const locator = page.locator('#component');
await expect(locator).toHaveClass(/(^|\s)selected(\s|$)/);
await expect(locator).toHaveClass(/(^|\s)row(\s|$)/);
\s could be replaced with (space), but it may be clearer to have the \s
Page(s)
https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-class
Description
The docs mention a 'relaxed regular expression' but doesn't define what 'relaxed' means. The existing example of
toHaveClass(/selected/)would also match class="selectedfoo row"I think it could be helpful if the example used the zero length word boundary pattern,
\b:Unfortunately,
\bconsiders-to be a boundary, so there is still some possible ambiguity. Perhaps/(^|\s)selected(\s|$)/would be better\scould be replaced with(space), but it may be clearer to have the\s