
Unit Testing Best Practices in AngularJS - andyshora
http://andyshora.com/unit-testing-best-practices-angularjs.html
======
andrewdavey
If you need end-to-end, browser-based, testing as well, check out Protractor:
[https://github.com/angular/protractor/blob/master/README.md](https://github.com/angular/protractor/blob/master/README.md)

It's built on top of WebDriverJS. I've been playing with it today and so far
it's working very well.

------
nickpresta
Just to add, [http://www.yearofmoo.com/2013/09/advanced-testing-and-
debugg...](http://www.yearofmoo.com/2013/09/advanced-testing-and-debugging-in-
angularjs.html)

A great article in a series of AngularJS articles, written by Matias Niemelä.

------
mvzink
Great article. One thing I wish got more coverage is testing directives: it's
already much easier than most DOM-testing methods (though it can't replace
selenium etc.), but doing it well and consistently has proven difficult and I
don't test most of my directives. For example, I had to modify the
triggerHandler function in Angular to allow sending fake key presses since it
didn't have a built in way (at least a few months ago) to specify the "which"
property on the event.

Also, If you're in Chicago, the Angular meetup group will be talking about
testing on November 20th: [http://www.meetup.com/AngularJS-
Chicago/](http://www.meetup.com/AngularJS-Chicago/)

~~~
Rodeoclash
This. I've come to the conclusion that directive testing falls under two
headers.

1, measuring the effects of the directive on the dom, e.g. rendering a list of
orders. This reflects the state of the application and

2, e2e testing of directives with a real browser.

However, I'm not sure this is correct! I'd like to see some best practices
listed by the Angular authors.

------
tegeek
Client side testable code is one of the pinnacle of AngularJS.

Reuseable declarative UI's through Directives, reuseable business logic throug
Services and view models (controllers) having only knowledge of views is a
really good for maintainablity of a complex javascript app. AngualrJS can beat
any framework out there (Backbone, Ember, etc.) when it comes to having
testable & manageable code.

If your product is going to be complex, AngularJS is a no-brainer deal.

~~~
mgr86
I'm curious, is there a strong reason to chose AngularJS over other non JS
frameworks. Say, Rails, Django, or one of the many other alternatives?

I realize this thread has me walking into the AngularJS den, but it is
something i've been passively curious about.

~~~
joshuacc
Generally speaking, you'd use Angular _with_ a backend framework.

Angular and other front-end frameworks are great for responding to user
interactions extremely quickly, because often you don't have to go back to the
server. And in addition when it does need to interact with the server, it is
often faster to respond because it doesn't need to fetch anything but JSON
data.

But that data needs to come from somewhere. And that's where
Rails/Django/Play/Symphony/whatever are used.

------
ldn_tech_exec1
This is great work, thanks for sharing!

