-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
Do you want to request a feature or report a bug?
Feature. React@16 made some changes that cause this issue.
What is the current behavior?
It's impossible to mock the console used by JSDOM. This is a problem because react-dom uses the browser to dispatch an event:
They do this
To preserve the expected "Pause on exceptions" behavior
It's kind of interesting actually. See the comments above the linked code.
But because of this, an error thrown in this way gets logged by JSDOM's VirtualConsole which is initialized in a different environment from my tests. This means it's impossible for me to mock it for an individual test.
That said, I can provide my own stub for JSDOM's VirtualConsole, but that will stub it for all tests which could lead to me missing legitimate errors being logged. Also, I can't make any assertions for my stub of VirtualConsole.
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.
Here's a repo: https://github.com/kentcdodds/jest-jsdom-react-console-issues
npm/yarn installnpm run test:1npm run test:2
The test:2 script uses the jest.custom-config.js config which provides the stub of VirtualConsole and you'll see it's not a problem in that situation, but I have the aforementioned problems.
What is the expected behavior?
I would like the console used to initialize JSDOM's VirtualConsole to be the same one that I have access to in my test so I can mock it.
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
See the repo above.
Thanks!