I'm starting to delve into some work with JavaScript and i'm trying to get a feel for how I should be writing testable JS code. My background is primarily Java which i'm quite comfortable with but I have no JavaScript experience. after some reading, I was going to use js-test-driver as my unit test framework, but I am open to suggestions here as well. With Java, my approach has always been breaking things down into small methods which accept something and return something... With JavaScript, I figured I would take a similar approach by separating any DOM manipulation and the actual logic into 2 separate functions. For example:
function sumValues(valA, valB) {
return (valA + valB);
}
function displayResult(result) {
document.getElementById('result').innerHTML = 'result';
}
So, any business logic would be easily testable.
Am I on the right track here or is there a better way to do things? Any recommended reading on this topic that is JS specific? Thanks for any ideas