Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The debug command is not printing the entire component. #503

Closed
felipediogo opened this issue Oct 14, 2019 · 12 comments
Closed

The debug command is not printing the entire component. #503

felipediogo opened this issue Oct 14, 2019 · 12 comments

Comments

@felipediogo
Copy link

  • react-testing-library version: 9.2.0
  • react version: 16.8.1
  • node version: 11.6.0
  • npm (or yarn) version: 6.9.0

Relevant code or config:

it("should render the component", async () => {
    const { debug, getByTestId } = render(
      <Component
        navigate={() => {}}
        location={{ search: "" }}
        setError={() => {}}
        setException={() => {}}
      />
    );
    await wait();
    debug();
});

What you did:

I'm just testing a component and doing a debug of the component

What happened:

The debug that was printed was just half of what I was expecting.

image

Reproduction:

Problem description:

The Debug is not printing the entire component, I think it is probably something related to the terminal.

Suggested solution:

@alexkrolick
Copy link
Collaborator

alexkrolick commented Oct 14, 2019

Output is truncated

https://testing-library.com/docs/dom-testing-library/api-helpers#debugging

Set the env var DEBUG_PRINT_LIMIT to increase the limit

@felipediogo
Copy link
Author

Thanks mate!

@eric-burel
Copy link

It should ideally be an option of the debug() command instead. For googlers: the limit is in number of chars, not lines, the default is 7000. So you may need smth like "20000" for instance

@dnorth
Copy link

dnorth commented Jun 23, 2020

Wow it took me so long to realize that my output was getting truncated... I was very confused as to why my component wasn't rendering properly. and now that i've realized it I agree with @eric-burel that this should be an option of debug().

@danawoodman
Copy link

I would argue that the default should be extremely high (or set to infinity) as setting an env var to increase this is strange and not intuitive. At least an optional param as @eric-burel mentions would be a big step forward.

@dnorth
Copy link

dnorth commented Sep 29, 2020

So as I was looking over this again, I realized that debug() is built on top of prettyDom and DOES have optional parameters including one for maxLength.

So if you do screen.debug(null, 20000) then it will print as expected, based on the documentation of that function.

@maciejmyslinski
Copy link

a neat trick is to use screen.debug(null, Infinity).

@larsenwork
Copy link

larsenwork commented Jun 3, 2021

FWIW it's

screen.debug(undefined, Infinity)

if you want to use correct types 😄

@evanjmg
Copy link

evanjmg commented Oct 25, 2022

still doesn't work in some cases

@mrossiml
Copy link

mrossiml commented May 15, 2023

This work for me:

screen.debug(undefined, Infinity, { highlight: false });

Note: if I do not put the "highlight: false" it does not print everything and it is cut off

I took it from this page:
https://blog.logrocket.com/using-react-testing-library-debug-method/

@bell-matthew
Copy link

This work for me:

screen.debug(undefined, Infinity, { highlight: false });

Note: if I do not put the "highlight: false" it does not print everything and it is cut off

I took it from this page: https://blog.logrocket.com/using-react-testing-library-debug-method/

Even using this command or the one above it my output is still cutoff. I think it's due to the async nature of my test and the fact that the next line is errorring for not being able to find the element, and the test is failing before the entire output is written? Not sure but I'm getting a ... at the end out my debug output before the error so it must be truncating the output still right?

@bell-matthew
Copy link

bell-matthew commented Jul 12, 2023

Okay confirmed. The truncated output was due to my screen.findAllByText() failing the test before the screen.debug() output was able to finish. I'm not super familiar with JS async stuff but there ought to be some way to make the screen.debug() block until it's finished writing to console, or have some kind of timed delay after the call to ensure the buffer is flushed to output?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants