1

I want to cleanup react tree and abort all of it's asynchronous tasks. The react tree is rendered using render function of React Testing Library. I know that you can use cleanup function to unmount react tree but that doesn't cancel all the asynchronous tasks.

The motivation: I am calling backend API to clean db after each test. If I don't remove all the async tasks after a test finishes, some API calls might occur after cleaning the db causing errors.

Noname
  • 4,432
  • 2
  • 10
  • 17

1 Answers1

1

This is a universal issue with javascript and promises, not specific to testing-library. To do this you would need to add additional logic wrapping your promises that fire when the component unmounts.

More info here.

bryce
  • 3,022
  • 1
  • 15
  • 19