0

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 ?

Ken White
  • 123,280
  • 14
  • 225
  • 444
HIT_girl
  • 785
  • 7
  • 23
  • try with approach mentioned in https://stackoverflow.com/questions/60481331/testing-img-onload-img-onerror-using-jest-and-react-testing-library – skyboyer Jan 23 '22 at 12:42
  • as for "download/parsing success" - what's the purpose here? I mean, is there a possibility then triggering `onLoad`(or at least, _not_ triggering `onError`) would lead to different results whether parsing succeeds/fails? – skyboyer Jan 23 '22 at 12:47

0 Answers0