react-testing-library: some portion of debug's output is not visible

JavascriptReactjsJestjsReact Testing-Library

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

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#L24

Solution 2 - Javascript

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)  

Solution 3 - Javascript

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:

Solution 4 - Javascript

Another option

screen.debug(undefined, Infinity);

Solution 5 - Javascript

If none of the other answers work for you, make sure it's not your terminal limit. For example VS Code only keeps 5000 lines in buffer. Try Mac OS terminal.

Solution 6 - Javascript

This worked for me:

debug(undefined, 300000);

It will give you the markeup of whatever you passed into render() as:

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

render(<MyComponent />);

You can read about more ways to help you with printing out the results, including prettifying the resulting markup at:

API doc for debug

Solution 7 - Javascript

This worked for me

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

screen.debug(debug(), 20000);

Solution 8 - Javascript

Also be sure your terminal allows you to scroll back that far. In iTerm2, I had my "Scrollback lines" set to 1000. Changed it to "Unlimited scrollback" and how life is goodiTerm2 scrollback lines iTerm2:

Solution 9 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmit ChauhanView Question on Stackoverflow
Solution 1 - JavascriptrrebaseView Answer on Stackoverflow
Solution 2 - JavascriptHaryonoView Answer on Stackoverflow
Solution 3 - JavascriptHeinrich FilterView Answer on Stackoverflow
Solution 4 - JavascriptlabsView Answer on Stackoverflow
Solution 5 - JavascriptpngView Answer on Stackoverflow
Solution 6 - Javascriptayooluwa alfonsoView Answer on Stackoverflow
Solution 7 - JavascriptBillie AngelovView Answer on Stackoverflow
Solution 8 - JavascriptAlan P.View Answer on Stackoverflow
Solution 9 - JavascriptSunil Kumar SinghView Answer on Stackoverflow