Part two in the series Test Driven Development with Javascript. By now you've probably read and heard a lot warning you off testing through the UI and testing the user interface generally. Those still holds true for Javascript so you may be wondering if there is anything left to test. Time for some code! Not very testable code function validate() { if(document.simple_form.name.value == "" || document.simple_form.email.value == "") { alert("Please fill out all fields before clicking submit!"); return false; } } In this there is some logic that is not directly tied to the UI. So there is something we can test. But it’ll need a bit of a rework to make it testable function isFormValid(formElement) { return (formElement.name.value != "" && formElement.email.value != ""); } function validate() { ...
About stuff I like and you should like more