I have a React component which internally creates a script
DOM element. There is a bunch of logic around handling onload
and onerror
events of this script. The onload
and onerror
handlers are internal to the component, and I can't pass them via props.
I would like to write some Jest tests for this code, but not sure how to mock the browser download functionality. I'd like to mock script download error, parsing error, and download/parsing success (without any network calls). Is there a way to do that ?