

Writing Testable Frontend Javascript Part 1 – Anti-patterns and their fixes - tosbourn
https://shanetomlinson.com/2013/testing-javascript-frontend-part-1-anti-patterns-and-fixes/

======
voidr
You can write a dummy backend endpoint, it shouldn't take too long in any
platform also you can use PhantomJS with CasperJS and/or Selenium to simulate
real user interactions which I think can be much more useful than simple unit
tests.

Also calling simple practices anti-patterns seems a little over-religious to
me, I don't believe in black and white mentality "if you are not doing
everything the 'right' way, you are doing it wrong", some stuff are just
simple and don't require heavily structured code to make it maintainable, if
it grows over time you will have to refactor it anyway. I think you can code
much more effectively if you always use the method that is best suited for
that particular use case.

If you can make your login form work with 10 lines of jQuery, I say go for it,
but if you are developing an advanced CRUD application, you are probably
better off with MVC or some other structured paradigm.

------
zacharydanger
What's the state of the art JavaScript automated testing stack look like? Does
anyone have an awesome example? I'd love to start testing my frontend code
with something other than browser refreshes.

~~~
joshuacc
I'm using grunt.js (0.4) with grunt-contrib-jasmine to test my front end JS on
the command line in phantomjs (headless webkit). If you also use grunt-
contrib-watch, you can have this happen every time you save your source/specs.

Example: <https://github.com/joshuacc/change-calculator>

------
griffindy
I've always liked testing ajax requests with sinon [1]. It injects its own
version of an XMLHttpRequest object to keep track of all requests, and you can
also send specific responses to test success and failure handling.

[1] <http://sinonjs.org/docs/#useFakeXMLHttpRequest>

