testing-library / webdriverio-testing-library

🕷️ Simple and complete WebdriverIO DOM testing utilities that encourage good testing practices.
16 stars 14 forks source link

Support for configure getElementError #52

Open k03mad opened 8 months ago

k03mad commented 8 months ago

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?