React-testing-library: debug() always returns undefined

Created on 21 Aug 2018  ·  5Comments  ·  Source: testing-library/react-testing-library

  • react-testing-library version: 5.0.0
  • react version: 16.4.2
  • node version: 8.11.3
  • npm (or yarn) version: 6.4.0

Relevant code or config:

      const Test = () => (
        <div>
            <div>hi</div>
            <div>other</div>
        </div>
      )
      const container = rtl.render(Test)
      console.log(container.debug())

What you did:

ran this in a test

running test in a jsdom environment

What happened:

undefined (debug doesn't do anything)

Reproduction:

Problem description:

docs imply debug() does something :)

Most helpful comment

You don't need the console.log. debug() does the log for you.

All 5 comments

You don't need the console.log. debug() does the log for you.

      const spy = jest.spyOn(console, 'log')
      container.debug()
      spy.mockRestore()
      console.log(spy.mock.calls)

logs []

      import * as dom from 'dom-testing-library'
      console.log(dom.prettyDOM(container.baseElement))

prints out the element tree.

I also copied from dist this code:

      Object.keys(_domTestingLibrary).forEach(function (key) {
        if (key === "default" || key === "__esModule") return;
        Object.defineProperty(exports, key, {
          enumerable: true,
          get: function get() {
            return _domTestingLibrary[key];
          }
        });
      });
      console.log(((0, _domTestingLibrary.prettyDOM)(container.baseElement)))

and that prints out. This is a weird bug, not sure what is going on

Hmmmm.... I'm not sure what's going on, but here's the code for it... It's pretty simple:

https://github.com/kentcdodds/react-testing-library/blob/master/src/index.js#L25

It's working for me 🤷‍♂️

@cellog can you provide an example repo that reproduces the problem?

Was this page helpful?
0 / 5 - 0 ratings