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

Protractor APIs


The main activities of an e2e test for any web page are to get the DOM elements of that page, interact with them, assign an action to them, and share information with them; then, the user can get the current state of the website. To enable us to perform all these actions, Protractor provides a wide array of APIs (some are from the web driver). In this chapter, we will look at some commonly used APIs.

In the previous chapter, we saw how Protractor works with an Angular project, where we had to interact with UI elements. For that, we used a few Protractor APIs, such as element.all, by.css, first, last, and getText. However, we didn't see or understand the workings of these APIs in depth. To understand the workings of APIs in Protractor is very simple, but in real life we will mostly have to work with bigger, complex projects. Hence, it's important that we understand and know more about these APIs in order to interact with the UI and play with its events.

Browser

Protractor works...