dimanche 4 février 2018

How to handle 'offsetWidth' for an element while using Enzyme to test a React component?

I created a React component that shows videos thumbnails and when clicking one of those thumbnails the video is loaded into a player. When the list of thumbnails is too big it adds scrolling buttons on both sides so the list scrolls left and right.

Both scrolling buttons use the offsetWidth of the wrapper as the value to scroll. This works fine but when testing it using Enzyme the component is mounted with offsetWidth = 0 so simulating a click on any of those buttons won't scroll the thumbs list and can't test if they work or not.

Which would be the right way of setting the component width when using Enzyme in order to test this scrolling buttons?

Aucun commentaire:

Enregistrer un commentaire