Mastering Web Application

(Rick Simeone) #1
Chapter 2

Inside the test folder

Automated tests are written to assert whether an application is operating properly, and
the test code is closely related to the functional code. As such, it shouldn't be surprising
that the structure of the test folder closely mimics the one of the src/app:


It is easy to see that the content of the test folder almost mirrors the root source
folder. All the tests libraries are located in their dedicated vendor folder and the
Karma runner's test configuration has its home too (config).


File-naming conventions


It is important to establish some file naming conventions to make navigation in
the code base easier. Here are a set of conventions often followed in the AngularJS
community and adopted in the book:



  • All the JavaScript files are named with the standard .js extension.

  • Partials get the .tpl.html suffix so we can easily distinguish them from
    other HTML files.

  • Test files get the same name as a file being tested and the suffix dependent
    on the test type. Unit tests would get the .spec.js suffix.


AngularJS modules and files


Now that our application is nicely organized into folders and files we can start
looking into content of the individual files. Here we are going to focus on JavaScript
files, their content and relation to AngularJS modules.

Free download pdf