testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.

Home Page:https://testing-library.com/dom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to avoid printing DOM to log on failures

IanVS opened this issue · comments

Describe the feature you'd like:

I am using this tool within Storybook, which means that it's not important for me to have a dump of the DOM output to the console every time a test fails, I can see the HTML as rendered in the page. And by having a long, long dump in the logs, it makes the test results when I run in CI more difficult to skim and find the actual error messages.

Suggested implementation:

Perhaps an option could be added to the configuration, which defaults to the current behavior, but allows turning off the DOM dump?

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

Hi @IanVS, sorry it took us time to get to this.
You can override the getElementError in the config to remove that.
I believe something like this should work:

  getElementError(message, container) {
    const error = new Error(
      [
        message,
        `Ignored nodes: comments, ${config.defaultIgnore}\n`,
      ]
        .filter(Boolean)
        .join('\n\n'),
    )
    error.name = 'TestingLibraryElementError'
    return error
  }

Thanks for pointing me in the right direction!