Chapter 10 ■ Deployment ConsiDerations
This time we named the module app.production.config, and this time it contains production specific-
configuration data. All that we need to do now is to tell our app which set of configuration data, or which module,
we want it it to use. This can be achieved with a single change, as shown in the following example.
var app = angular.module('app', ['ngRoute', 'ngAnimate', 'app.development.config']);
In this particular case, we have provided our app with the development configuration data by specifying
app.development.config as a dependency. The code that we are deploying to the production server would use
app.production.config.
Testing
Testing is a huge topic in modern software development, and one that we have not touched on very much in this
book. We barely have the time to do the topic justice, but I believe it is well worth singling out because AngularJS is
designed with testability in mind, and testing is so very important.
There are several schools of thought about how and when to test—all valid and all with their own pros and cons.
At a very high level the choices are generally one of the following:
• Behavior-Driven Development (BDD): This approach dictates that we should write our
tests first. In this scenario, we write tests to match the functionality that we will produce in
the future.
• Write-Behind Testing (WBT): This approach leaves testing until last, where we confirm the
functionality works as expected after we have produced the code that is responsible for it.
• Writing tests to black-box test the functionality of the overall system.
Two extremely popular approaches these days are Behavior-Driven Development (BDD) and its cousin
Test-Driven Development (TDD). Both are conceptually similar in that unit tests are written first and application code
is produced later that will, once correct, pass these tests. This approach requires discipline and learning at least one
unit-testing framework. A good unit-testing framework will make it easier to write and run your tests.
■ Note the main differences between tDD and BDD are subtle but significant, owing to variations in the underlying
mindset of the developer. many consider BDD to be an improved version of tDD. i don't think one is necessarily better
than the other, and both are valid options.
For the purposes of getting a general sense of what unit testing and Behavior-Driven Development is all about,
we will consider a simple set of tests that revolve around some identified requirements for a typical login process.
We will use Jasmine, a behavior-driven development framework for testing JavaScript code. Keep in mind, in this
scenario, we have not yet written any application code; we are instead going to write an initial set of unit tests that we
know we will need to run once we have produced the logic. In fact, in Listing 10-5, the Jasmine tests start out empty too.
Listing 10-5. An initial look at a set of tests
describe('user login form', function() {
it('ensures invalid email addresses are caught', function() {});
it('ensures valid email addresses pass validation', function() {});
it('ensures submitting form changes path', function() { });
});