Getting started with testing
When making a change of this nature, it’s a good practice to write an automated test to verify that the feature is implemented correctly.
Our first test
trainjs generate controller command automatically generated an end-to-end test file to get us started
The default tests for the staticPages controller
To begin our testing cycle, we need to run our test suite to verify that the tests currently pass. We can do this with the protractor, an end-to-end test framework for AngularJS
As required, initially our test suite is passing.
Our first step is to write a failing test for the About page.
As required, the test initially fails
Now that we have a failing test, we’ll use the failing test’s error messages to guide us to a passing test, thereby implementing a working About page.
We can get started by examining the error message output by the failing test:
The error message here says that no route matches the desired action/controller combination, which is a hint that we need to add the state to the
StaticPagesAboutCtrl in the
As before, our test suite is still failing, but the error message has changed again:
This indicates a missing template. We need to create a new file called about.html in the
The generated view for the Home page.
At this point, our test suite is passing