Hacker News new | past | comments | ask | show | jobs | submit login
Test-driving your Javascript for fun and profit (wealthfront.com)
15 points by mattbaker on Feb 1, 2011 | hide | past | favorite | 2 comments



The first thing you’ll notice is that magical comment at the top of our test. jsTestDriver takes a comment beginning with ":DOC +=" and adds the contents of the comment as a DOM fragment to the page, allowing us to test against it. It’s a simple and effective way of providing DOM fixtures to test any code that does DOM manipulation.

OK, that is just gratuitous "magic". Nobody picking up that code to look at is going to realise that the comment is meaningful and necessary for the test. What is the advantage of doing that instead of calling a function to do the work, passing the DOM fragment as a parameter. Even if the parser that currently uses the comment has to identify the function call and treat it in the same way as the comment, at least by doing it as a function call, you have signalled to any user that the comment is significant.

/rant


I agree. If you can change or delete comments the code stops working, there's something wrong. It's totally unexpected.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: