jeudi 27 décembre 2018

Scroll and Width in JSDOM not implemented due to no layout in jsdom?

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:

  1. global.document.dispatch(new Event('scroll')) [this was done after adjusting the scroll position]

  2. 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