Aljullu / react-lazy-load-image-component

React Component to lazy load images and components using a HOC to track window scroll position.
https://www.npmjs.com/package/react-lazy-load-image-component
MIT License
1.44k stars 109 forks source link

onLoad doesn't trigger in jest test #85

Open ArinCantCode opened 3 years ago

ArinCantCode commented 3 years ago

Bug description I'm trying to write a test for my component which uses this library. I'm using lazy loaded image as a background of a component within the parent component, onLoaded callback i'm setting a flag that renders rest of the content. (otherwise the UI looks weird without the background).

Problem is the onLoaded doesn't get triggered or gets triggered too late and my test fails because it doesn't find the content im looking for.

Code (LazyImage is just a wrapper around the lib):


const [showContent, setShowContent] = useState(false)

return (
    ....code
     <LazyImage
            src={bannerImage.url}
            onLoaded={() => {
              setShowContent(true)
              ReactTooltip.rebuild()
            }}
          />
          {showContent && <SingleDealContent {...props} />}
    ....code
)

in my test when i search for the component on the page it doesn't find it. However if i remove the showContent it works wonders. (UI works perfectly fine when rendered in the app)

Is there a way in which this onLoaded gets triggered?