react-lazy-load-image-component icon indicating copy to clipboard operation
react-lazy-load-image-component copied to clipboard

onLoad doesn't trigger in jest test

Open ArinCantCode opened this issue 3 years ago • 0 comments

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?

ArinCantCode avatar Jan 02 '21 15:01 ArinCantCode