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

auto cleanup will break down testing in mocha & esm environment #375

Closed
DaveWelling opened this issue May 29, 2020 · 2 comments
Closed

auto cleanup will break down testing in mocha & esm environment #375

DaveWelling opened this issue May 29, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@DaveWelling
Copy link

  • react-hooks-testing-library version: 3.2.1
  • react-test-renderer version: 16.9.0
  • react version: 16.13.1
  • node version: 10.13.0
  • npm (or yarn) version: 6.9.0

Relevant code or config:

The problem is exactly this:
testing-library/react-testing-library#614
but with this package instead of the react-testing-library
And the solution is the exactly the same (I tested it by hacking the node_modules).

Go into the flush-microtasks.js file and literally change this:
enqueueTask = nodeRequire('timers').setImmediate;
to this:
enqueueTask = nodeRequire.call(module, 'timers').setImmediate

What you did:

Run any mocha test using the react-hooks-testing-library and using esm.

What happened:

The library hangs the mocha tester if you are using esm.

Reproduction:

Run any test at all with this library, mocha and esm.

Problem description:

You get this error message (from flush-microtasks.js):
This browser does not have a MessageChannel implementation, ' + 'so enqueuing tasks via await act(async () => ...) will fail. ' + 'Please file an issue at https://github.com/facebook/react/issues ' + 'if you encounter this warning.'

It hangs the cleanup (for instance mocha afterEach will never finish).

Suggested solution:

Go into the flush-microtasks.js file and literally change this:
enqueueTask = nodeRequire('timers').setImmediate;
to this:
enqueueTask = nodeRequire.call(module, 'timers').setImmediate

@DaveWelling DaveWelling added the bug Something isn't working label May 29, 2020
@mpeyper
Copy link
Member

mpeyper commented May 29, 2020

I see. I stole my implementation from react-testing-library in the first place, so bringing it inline with their updates is a good idea.

Fancy submitting a PR to fix this up?

DaveWelling pushed a commit to sstid/react-hooks-testing-library that referenced this issue Jun 1, 2020
@DaveWelling
Copy link
Author

Per your request, I have submittted an PR. #377

@mpeyper mpeyper closed this as completed Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants