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

Differences in scope/context when calling via CLI vs. include #54

Open
dvbsknd opened this issue Nov 4, 2020 · 0 comments
Open

Differences in scope/context when calling via CLI vs. include #54

dvbsknd opened this issue Nov 4, 2020 · 0 comments

Comments

@dvbsknd
Copy link

dvbsknd commented Nov 4, 2020

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:

"test:client": "npx mocha -r jsdom-global/register -r @babel/register -recursive 'client/**/test.js'",

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:

image

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:

Screen Shot 2020-11-05 at 8 35 21 am

...

Screen Shot 2020-11-05 at 8 34 55 am

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:

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant