[Docs]: Custom matcher example doesn't work when you have a multiple element exception
Page(s)
https://playwright.dev/docs/next/test-assertions#add-custom-matchers-using-expectextend
Description
The example in the docs above doesn't work if for example the locator has multiple elements - the exception gets swallowed.
You can add
} catch (e: any) {
// if we are testing more than 1 locator we need to show that error message
if (e.message.includes('strict mode')) {
throw e;
}
matcherResult = e.matcherResult;
}
to work around it but I am sure there are other exceptions I am missing by just testing for strict mode.
other example in the same example: https://github.com/microsoft/playwright/issues/34390 original request for this documentation: https://github.com/microsoft/playwright/issues/15951#issuecomment-1195658478 issue raised but I was told off for not following the template: https://github.com/microsoft/playwright/issues/34327 issue raised but I was told off because there are multiple issues with the example and you want seperate bugs: https://github.com/microsoft/playwright/issues/34350
As I said originally I think making this custom assertion work properly is complicated - I'd prefer playwright exposed a way to do it rather than have a very complicated example.