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

Bug: Cypress Component testing on React logs console logs recursively #232

Closed
RomelClavel opened this issue Jan 15, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@RomelClavel
Copy link

RomelClavel commented Jan 15, 2024

When running a component test suite on cypress with the default setup, any console event will be printed into console recursively until there is a RangeError: Maximum call stack size exceeded.

The conditions for this behavior to occur are the following:

  • There need to be at least 2 component tests in the suite. The undesired behavior does not trigger if there is only one test being run.
  • There needs to be a one or more console events (log/info/warn/error) in the test case itself or in any component that's being rendered.

Here is a simple example of the test suite that leads to this behavior:

describe("Recursive logging on console events", () => {

  const Title = () => {
    return <h1>title</h1>;
  };

  it("Component test 1", () => {
    cy.mount(<Title />);
    console.warn("warning");
    cy.get("h2");
  });

  it("Component test 2", () => {
    cy.mount(<Title />);
    console.warn("warning");
    cy.get("h2");
  });
})

Currently the only way I have of mitigating this unwanted behavior is excluding the console events setting the Collect Types option in the Install Logs Collector. Like so:


require("cypress-terminal-report/src/installLogsCollector")({
  collectTypes: ["cy:log", "cy:xhr", "cy:request", "cy:intercept", "cy:command"]
});
@RomelClavel RomelClavel changed the title Cypress Component testing on React logs console logs recursively Bug: Cypress Component testing on React logs console logs recursively Jan 15, 2024
archfz added a commit that referenced this issue Jan 19, 2024
@archfz archfz added the bug Something isn't working label Jan 19, 2024
@archfz
Copy link
Owner

archfz commented Jan 19, 2024

Fixed in 5.3.11

@archfz archfz closed this as completed Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants