34

I am using react jest with react testing library to test my component. I am facing a weird issue. I am usng debug return by render from testing-library.

test('component should work', async () => {
  const { findByText, debug } = render(<MyComponent />);
  const myElement = await findByText(/someText/i);
  debug();

});

enter image description here

As you can see in the screenshot there are incomplete dev and closing tags for parents are missing.

Amit Chauhan
  • 3,990
  • 1
  • 15
  • 30
  • 3
    have you tried increasing the `DEBUG_PRINT_LIMIT` as mentioned in [here](https://testing-library.com/docs/dom-testing-library/api-helpers#debugging) – uday Jan 16 '20 at 06:28
  • @uday no luck with DEBUG_PRINT_LIMIT, still same issue. – Amit Chauhan Jan 16 '20 at 08:14

5 Answers5

35

You need to change the value of DEBUG_PRINT_LIMIT env variable (default is 7000).

For example, run your tests with: DEBUG_PRINT_LIMIT=10000 yarn test

Source: https://github.com/testing-library/dom-testing-library/blob/master/src/pretty-dom.js#L22

rrebase
  • 1,519
  • 1
  • 11
  • 21
16

I am using this version: "@testing-library/react": "^11.0.4"

able to do just like below, we can change 300000 as the max length of output.

debug(undefined, 300000)  
Pier-Luc Gendreau
  • 11,989
  • 4
  • 51
  • 60
Haryono
  • 700
  • 8
  • 10
4

The second argument of the debug() function can be used to set maxLengthToPrint.

E.g. to print everything in myElement using the recommended screen approach:

import {render, screen} from '@testing-library/react'

render(<MyComponent />);
const myElement = await screen.findByText(/someText/i);

const maxLengthToPrint = 100000
screen.debug(myElement, maxLengthToPrint);

See:

Heinrich Filter
  • 4,545
  • 1
  • 28
  • 29
1

This worked for me

const history = createMemoryHistory()
const { debug } = renderWithRedux(
    <Router history={history}>
        <SideBar />
    </Router>
, state);

screen.debug(debug(), 20000);
0

Adding on top of answer by @Haryono

Also make sure you don't have silent flag set in scripts

"test": "jest --config jest.config.js --silent";

Removing silent flag should work.

Note: I think silent flag supresses warnings and debug outputs