I asked this question on the stackoverflow site: https://stackoverflow.com/questions/27469850/has-client-side-javascript-unit-testing-gotten-lost ...but I think it's a little to open ended. So instead...
Does it make sense to unit test client-side Javascript outside of the browser environment?
A few notes to inform readers: 1. I am not saying remove the browser from all testing procedures, just unit testing specifically.
- I know about using Node testing frameworks with Jsdom and am not looking for a framework suggestion.
I want to know what people think about unit testing outside of the browser. My main concerns for unit testing using a browser are:
It's slower. This leads to longer feedback loops, devs will run the tests less often and discourages the use of tdd.
Incorporating the DOM is a part of integration testing, right?
Setting up a test environment in a browser can be a pain in the rear. E.g. loading modules and tests, keeping the dom clean, worrying about side effects like XHR, localStorage, cookies etc.
It confuses what we are actually testing at the unit layer. E.g. Am I testing this view renders the elements I'm expecting or am I testing this view renders when I'm expecting it to?
Testing in the browser is important but isn't that the responsibility of integration/functional tests? It makes more sense to me to run unit tests outside of the browser, mock/stub all side effects such as the DOM, XHR etc.
To repeat my question: Does it make sense to unit test client-side Javascript outside of the browser environment?
Feedback is appreciated, just looking for some clarity, thanks!