Duck-Angular updated for AngularJS 1.2.9, plus a quick recap

Update

Since publishing the series of posts on using Duck-Angular for unit testing controller, views, and bindings (Part 1, Part 2, Part 3, and Part 4), I’ve upgraded Duck-Angular and the AngularJS-RequireJS-Seed to support AngularJS 1.2.9. Below is just a quick recap of some of the things I’ve talked about already. There is more detail in the links above.

Unit Testing and Application Patterns

  • Using a module loader lets you test a controller, service, etc. in isolation without having to bootstrap AngularJS app.
  • Using a module loader allows for loading third-party dependencies without having to declare them as AngularJS objects (best of both worlds).
  • Using RequireJS makes minification a no-brainer.
  • Don’t pollute the Javascript global namespace (anything like window.*). You can isolate your entire application from external pollution.
  • Simplify testing promises using Mocha-as-Promised, Chai-as-Promised, etc. Jasmine-as-Promised also exists.
  • If you’re testing on anything below IE9, don’t have console.log() in your code.
  • Referring to router paths directly like <a href="\#/route1"/> may lead to infinite $digest loop errors.
    • Replace that with ng-click which does the actual navigation.
    • Or, add target=”_self” attribute to anchor link.
  • If you’re still using AngularJS 1.0.x and it is not too late, move to AngularJS 1.2.x now. There are quite a few things that are better, for example:
    • AngularJS 1.2.x has request interceptors (1.0.x had only response interceptors).
    • Many bug fixes for IE. Plus extra incentive to not use IE8 any more, since 1.3 and up will no longer necessarily work on IE8.
  • Don’t manipulate the DOM in Javascript.
    • Bind DOM states to $scope variables (ng-show, etc.)
    • Isolate DOM-manipulating functions that you must have in their own modules.