Mastering Web Application

(Rick Simeone) #1

Building and Testing


While using the debugger statement don't forget to turn on your
developer tools in your favorite browser. Otherwise a browser
won't pause and you won't be able to debug tests.

Sometimes it might be easier to just print values of some variables on a console.
AngularJS mocks come with one convenient method for such occasions angular.
mock.dump(object). In fact the dump method is also exposed on the global (window)
scope so we could simply write dump(object).


Summary


This chapter prepared us for writing real-life applications with AngularJS. At the
beginning we went over the details of the sample application; its problem domain and
the technical stack. The rest of this book is filled with the examples inspired by the
sample application for managing projects using the SCRUM methodology. To write
this application we are going to use a JavaScript-based (or at least JavaScript-friendly),
open source stack: hosted MongoDB as a persistence store, node.js as the server-side
solution and obviously AngularJS as the front-end framework.


We spent a considerable amount of time discussing build-related problematic
philosophy behind a perfect build system and its practical implementations. We've
chosen the JavaScript-based (and node.js powered) grunt.js to write sample build
scripts. Looking into the build inevitably leads us to look into the organization of
files and folders in the sample project. We've chosen a directory structure that plays
nicely with the AngularJS module system. After pondering different ways of declaring
AngularJS modules and providers, we've settled on the syntax that avoids confusion,
doesn't pollute the global namespace, and keeps our build system complexity at
reasonable levels.


The benefits of automated testing are well known and understood these days. We are
lucky since AngularJS puts strong emphasizes on testability of the code written using
the framework. We saw that AngularJS comes with the complete testing offering
tools (Karma runner), integration with the existing testing libraries (Jasmine), and the
built in dependency injection system that makes it easy to test individual objects in
isolation. We saw how to test AngularJS artifacts in practice as well testing AngularJS
services and controllers should have no secrets for you at this point. With all the
solutions in place it is easy to put in place a very nice, lightweight testing workflow.


So far we've learned AngularJS basics and saw how to structure a non-trivial
application. We can now use this foundation to add concrete, real-life elements.
Since any CRUD application needs to work with the data fetched from a persistent
store, the next chapter is devoted to the AngularJS-way of communicating with
various back-ends.

Free download pdf