Closed ChromeQ closed 2 years ago
I noticed you commented out some of these properties https://github.com/trurl-master/jsdom-testing-mocks/blob/52a5b4ce70ab978f39adf07c061ba8c4061908c1/src/mocks/intersection-observer.ts#L63
Is this something you considered or tried but did not work?
I can get around it for now but would like to avoid the ts-ignore & eslint-disable if possible:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line Until `jsdom-testing-mocks` allows more props
intersectionObserver.enterNode(screen.getByText('foo'), { intersectionRatio: 1 });
Hey @ChromeQ
Thanks for the issue. You are correct. It would be better to have correct definitions. Probably I just forgot to implement them as it wasn't relevant to me at the moment. I will take a look at it in the next few days, or if you have time, you can make a quick PR
I am happy to open a PR very soon, just checking this wasn't something you had spent time on and found it to be impossible. Thanks
@ChromeQ published under 1.2.2. Please check that it works for you
Thank you very much for your contribution! ❤️
Updated and can confirm it is working! Thanks
I am using
mockIntersectionObserver.enterNode
and the type allows passing a desc which is typed as IntersectionDescription This type is too basic, some callbacks need to know more about the "entry" such as theintersectionRatio
orboundingClientRect
I realise this is probably difficult to do as jsdom does not render actual layouts so a lot of these cannot be calculated easily (or at all)
However you do spread the desc in the enter/leave helper functions,
So I propose that the IntersectionDescription should look a lot more like the TS lib definition with all optionals so they are spread into your callback, then it is up to the developer to set the correct values as the test may require