I am trying to write a test case for a component which checks if a function bound to a component is called if scroll is triggered on window object.This is not using react framework although I am using JEST as my testing framework which uses JSDOM since it is very good and fast.
The first problem is the scroll is not getting triggered at all. Read about it in a lot of github issues but had no luck.
The second problem is that I have set a width to one of the elements to 1000 px which is a sandbox element in jsdom using jest. But when I add another element below it which is the result of the rendered component the DOMElement function of getClientBoundingRect still returns all zeros.
tried a couple of things which did not work:
-
global.document.dispatch(new Event('scroll')) [this was done after adjusting the scroll position]
-
After rendering my component which has around 19 li elements in it [each li element has a 10px x 10px image and a title], I am trying to check the height of my component to scroll to that position, but unluckily everything is coming to 0.
Is there any other way to test or cover a function which is called on window.scroll using jsdom/jest, I dont want to use phantomjs.
Aucun commentaire:
Enregistrer un commentaire