webdriverio-testing-library icon indicating copy to clipboard operation
webdriverio-testing-library copied to clipboard

Support for configure getElementError

Open k03mad opened this issue 11 months ago • 0 comments

Hello 👋

If the testing-library is unable to find an element using getByRole or any other method, a lengthy stacktrace is generated when the test fails.

I attempted to configure the getElementError for a custom message as per the documentation: https://testing-library.com/docs/dom-testing-library/api-configuration/#getelementerror

  // I am trying this in the tests of this library to ensure the issue is not related to our project
  // webdriverio-testing-library/test/async/configure.e2e.ts
  it('getElementError', async () => {
    configure({
      getElementError: (message, container) => {
        const customMessage = 'my custom message';
        return new Error(customMessage)
      },
    })

    const {getByRole} = setupBrowser(browser)

    await getByRole('button', {name: 'no such name'});
  })

However, I am not seeing 'my custom message' displayed when the test fails with an element not found error. Am I doing something incorrectly, or this option is not supported yet?

k03mad avatar Mar 04 '24 11:03 k03mad