Book Image

Angular Test-Driven Development - Second Edition

By : Md. Ziaul Haq
Book Image

Angular Test-Driven Development - Second Edition

By: Md. Ziaul Haq

Overview of this book

<p>This is a complete guide that shows you testing techniques with Karma that will help you perform unit testing and end-to-end testing with Protractor. It will show you how to optimize your Angular development process using TDD techniques and ensure your final project is free of bugs. All examples in this book are based on Angular v2 and are compatible with Angular v4.</p> <p>We start by reviewing the TDD life cycle, TDD in the context of JavaScript, and various JavaScript test tools and frameworks. You will see how Karma and Protractor can make your life easier while running JavaScript unit tests. We will enable you to build a test suite for an Angular application and build a testable medium-to-large scale Angular application by handling REST API data.</p> <p>Building on the initial foundational aspects, we move on to testing for multiple classes, partial views, location references, CSS, and the HTML element. In addition, we will explore how to use a headless browser with Karma. We will also configure a Karma file to automate the testing and tackle elements of Angular (components, services, classes, and broadcasting) using TDD.</p> <p>Finally, you will find out how to pull data using an external API, set up and configure Protractor to use a standalone Selenium server, and set up Travis CI and Karma to test your application.</p>
Table of Contents (15 chapters)
Angular Test-Driven Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Getting ready to communicate


We will follow a different approach in this chapter, as we've already learned the TDD approach. We developed a small project in the previous chapter, and our plan is to work with that project and make it better in order to present it to the world.

So, before the walk-through, we will have to review and identify any problems and the scope for improvement of the project. To do so, we have to be confident of the code base of the search application.

Loading the existing project

To start with, we will copy the project from Chapter 7, Flip Flop, which was originally from https://github.com/angular/quickstart, and rename it angular-member-search.

Let's proceed and get ready to run it:

$ cd angular-member-search
$ npm install 
$ npm start

To confirm the installation and run the project, the application will automatically run it in a web browser.

Here is the output we should get when we will run the project:

Oh! We have our end-to-end test ready in the project. Before we...