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

waitForValueToChange: ReferenceError MessageChannel is not defined #647

Closed
andrewagain opened this issue Jul 7, 2021 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@andrewagain
Copy link

andrewagain commented Jul 7, 2021

  • react-hooks-testing-library version: Tried 6.0.0 and 7.0.1
  • react version: Tried 16.12.0, 16.14.0, and 17.0.1
  • react-dom version (if applicable): Always kept the same as react version
  • react-test-renderer version (if applicable): Always kept the same as react version
  • node version: v14.15.5
  • npm (or yarn) version: yarn 1.22.10

Relevant code or config:

    const x = renderHook(() => useMyCustomHook());
    await x.waitForValueToChange(() => x.result);

Also tried:

    const x = renderHook(() => useMyCustomHook());
    return x.waitForValueToChange(() => x.result).then(() => {
       // do nothing
    });

What happened:

  MyCustomHook
Warning: 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.
    1) myfirsttest


  0 passing (1s)
  1 failing

  1) MyCustomHook
       myfirsttest:
     ReferenceError: MessageChannel is not defined
      at enqueueTaskImpl (webpack:///./node_modules/react-test-renderer/cjs/react-test-renderer.development.js?:14656:23)
      at enqueueTask (webpack:///./node_modules/react-test-renderer/cjs/react-test-renderer.development.js?:14663:10)
      at flushWorkAndMicroTasks (webpack:///./node_modules/react-test-renderer/cjs/react-test-renderer.development.js?:14893:5)
      at eval (webpack:///./node_modules/react-test-renderer/cjs/react-test-renderer.development.js?:14974:11)

Research:

Looks like a similar issue in React has a workaround here: facebook/react#20756 (comment)

I tried that workaround and it didn't help. Also that workaround looks like it is for Node 15 and I am on Node 14.

The problem only seems to happen if I use await.

@andrewagain andrewagain added the bug Something isn't working label Jul 7, 2021
@andrewagain andrewagain changed the title ReferenceError: MessageChannel is not defined waitForValueToChange: ReferenceError MessageChannel is not defined Jul 7, 2021
@mpeyper
Copy link
Member

mpeyper commented Jul 7, 2021

Hi @ahfarmer,

Can you provide some more details on how you are running the tests. I can see webpack so presumably you are bundling. Are you running the tests in a browser or still in node?

Another things to try is using the @testing-library/react-hooks/dom import. I've found some of the "fixes" in react only work in react-dom and react-test-renderer gets forgotten/ignored.

@andrewagain
Copy link
Author

Thanks for the response @mpeyper !

I actually worked around this issue for the time being by updating Node from 14.15.5 to v16.4.2.

If I'm not able to update node everywhere I'll give the /dom import a try.

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