lundi 18 mai 2015

How to write testable javascript code?

I have a large flat javascript file containing many functions. Some functions are executed when some DOM element is clicked, for example. The only library my code uses is jQuery.

Do I need a framework for this? Can someone provide examples? I was thinking of creating Controller classes move my functions into different controllers that expose public functions, etc. Then test those controllers. However, those controllers interact with DOM elements via jQuery, so my confussion starts right there. How can I test that the controller is doing what's supposed to do? For example, a controller that scrolls the page down after some callback is executed, etc. How can I test that?

So is there a better way to write javascript for testability ?

Aucun commentaire:

Enregistrer un commentaire