-
Notifications
You must be signed in to change notification settings - Fork 231
Closed
arvinxx/components
#5Labels
Description
react-hooks-testing-libraryversion: 5.0.0react-test-rendererversion: not installedreactversion: 17.0.1nodeversion: 17.0.1npm(oryarn) version:[email protected]
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 frameworks 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.