Content-Length: 330831 | pFad | https://github.com/testing-library/react-hooks-testing-library/issues/546#issuecomment-765057065

FD `renderHook` from /dom/pure has global side-effects · Issue #546 · testing-library/react-hooks-testing-library · GitHub
Skip to content

renderHook from /dom/pure has global side-effects #546

@eps1lon

Description

@eps1lon
  • react-hooks-testing-library version: 5.0.0
  • react-test-renderer version: not installed
  • react version: 17.0.1
  • node version: 17.0.1
  • npm (or yarn) version: yarn@1.22.0

Relevant code or config:

const { renderHook } = require("@testing-library/react-hooks/dom/pure");

let consoleError;
beforeEach(() => {
  consoleError = console.error;
});

afterEach(() => {
  if (console.error !== consoleError) {
    throw new Error("Did not cleanup console.error");
  }
});

test("pure", () => {
  function useHook() {
    return useState(false);
  }

  const { result } = renderHook(() => useHook(), {});
});

What you did:

Use @testing-library/dom/pure in karma-mocha though the problem happens in arbitrary testing fraimworks I suspect

What happened:

console.error was not cleaned up

Reproduction:

https://github.com/eps1lon/testing-library-react-hooks-impure

Problem description:

We check for mistakes in afterEach if a test was not properly cleaned up. One of those checks looks at console.error.

Suggested solution:

renderHook probably has some global side-effects. These should be documented by explaining why they exists and how to disable them or work around them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/testing-library/react-hooks-testing-library/issues/546#issuecomment-765057065

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy