Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Oh boy, jQuery soup. Sounds fun to unit test.


Unit testing has been done with jQuery since it came out in 2006. Rather than one giant monolithic app, jQuery promotes putting things into plugins or separate libraries.

What stops you from unit testing function calls? Nothing.


It also promotes procedural code for modifying DOM, not declarative. This makes unit testing much harder imo, since you're into the realm of either working against a real DOM, or mocking everything.


In the example from the article we are talking about, it would be easy to mock out the one function call for modules A, and B. There's no DOM manipulation in the article.

Keeping DOM modifying code separate is good practice in either case. Then you don't need to involve the DOM in much of your code. Doing end to end testing is also completely ok to do.

It's worth repeating, so I'll say it again... It's better to keep DOM manipulation code separate. Then you don't need to mock, or simulate anything. Except where needed. You do need to test DOM manipulating code somehow.

AngularJS also uses the DOM in their tests: https://github.com/angular/angular.js/blob/master/test/ngAni... Here's a jquery-ui test for comparison: https://github.com/jquery/jquery-ui/blob/master/tests/unit/s...


With React there really is no notion of manipulating DOM, so there is no need to test it.


Of course it eventually touches the DOM. It also has a virtual DOM.


Right, but it's declarative. You only care about how the DOM looks right now.




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

Search: