You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I hope I'm not missing something obvious but have spent quite a bit of time trying to solve this before creating an issue.
I am using mocha as my test runner for historical reasons and attempting to test React components using @testing-library/react. I've come across what seems to be a scope/context issue between the command-line --require directive vs. including directly in the test file.
I've pasted the full script in case there's something else that can be spotted. When I run the script above on a test that does not explicitly importjsdom-global I get an output like this:
Note that screen.debug() outputs an empty <body /> element.
If I remove the -r jsdom-global/register option and explicitly add import 'jsdom-global/register' in my test file, I get:
...
As you can see, in the second example including jsdom-global/register via an explicit import in my test file appears to make the DOM available to screen, but requiring it via mocha on the command line does not.
Both methods appear to make an identical document global available:
The text was updated successfully, but these errors were encountered:
I hope I'm not missing something obvious but have spent quite a bit of time trying to solve this before creating an issue.
I am using
mocha
as my test runner for historical reasons and attempting to test React components using@testing-library/react
. I've come across what seems to be a scope/context issue between the command-line--require
directive vs. including directly in the test file.My
npm test
script is as follows:I've pasted the full script in case there's something else that can be spotted. When I run the script above on a test that does not explicitly
import
jsdom-global
I get an output like this:Note that
screen.debug()
outputs an empty<body />
element.If I remove the
-r jsdom-global/register
option and explicitly addimport 'jsdom-global/register'
in my test file, I get:...
As you can see, in the second example including
jsdom-global/register
via an explicitimport
in my test file appears to make the DOM available toscreen
, but requiring it viamocha
on the command line does not.Both methods appear to make an identical
document
global available:The text was updated successfully, but these errors were encountered: