Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Duck-Angular Updated for AngularJS 1.2.9, Plus A Quick Recap

DZone's Guide to

Duck-Angular Updated for AngularJS 1.2.9, Plus A Quick Recap

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

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.2.x 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.

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Published at DZone with permission of Avishek Sen Gupta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}