react-hooks-testing-library: TypeError: Cannot destructure property 'error' of 'results[(results.length - 1)]' as it is undefined. [Suspense]

  • react-hooks-testing-library version: 5.0.2
  • react version: 17.0.1
  • react-dom version (if applicable): 17.0.1
  • react-test-renderer version (if applicable):17.0.1
  • node version:14.13.1
  • npm (or yarn) version:1.22.5

Relevant code or config:

expect(result.error).toBe(null);

What you did:

Directly after the renderHooks() line with a function that throws a Promise

What happened:

Reproduction:

result.error just after a hook that suspends (don’t await the resolution of suspense).

result.current was fixed in https://github.com/testing-library/react-hooks-testing-library/commit/dc21e5947a54adfaf348bfeaeab56d37a4e7e2bb but result.error was not.

Problem description:

Suspense is the most important use of this library

Suggested solution:

Do the thing in https://github.com/testing-library/react-hooks-testing-library/commit/dc21e5947a54adfaf348bfeaeab56d37a4e7e2bb but apply to all members

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 64 (64 by maintainers)

Most upvoted comments

Oh wow, I didn’t realize it wasn’t actually a promise. I kinda expected typescript to complain about awaiting something that isn’t a promise. Well, thanks for all your help - upgrade complete! 😃

rerender() is what i can use to reset error boundary?

Thanks so much for the investigation - this looks to be super helpful. Unfortunately I have to wrap up some other stuff for now so I have to put a pause on this til probably end of the week. I’ll update on whatever I find there. Thanks again!