about this book

Testing Angular Applications exists to help developers better understand one of the trickier parts of using the power of Google’s Angular framework: writing testable, reliable code. Angular departs wildly from the earlier AngularJS framework, introducing developers to a slew of new concepts not familiar from AngularJS or any other JavaScript framework. Writing unit tests and end-to-end tests requires a deeper knowledge of Angular than even the most heroic of tutorials can convey. Angular written for production should be backed by a set of reliable and useful tests, and with this book, we equip the reader with the knowledge to deliver those tests.

Who should read this book

Whether you’re an experienced developer contributing to an enterprise-scale Angular application or new to Angular and hoping to gain a deeper understanding of the framework, this book will help you understand the fundamentals of writing testable code. Angular is evolving at a rapid pace, faster than the official documentation can match. Supplemental material such as this book goes beyond the online documentation by providing step-by-step examples that explain not only the how but also the whys of unit testing in Angular. This book assumes a comfortable knowledge of JavaScript and some knowledge of TypeScript, a superset of JavaScript that adds a variety of new language features.

This book reflects many hours of real-world experience understanding and applying the Angular framework for both unit and end-to-end tests. As authors, we’ve read the online documentation, delved into the Angular source code, upgraded Angular multiple times (along with the example application written for this book), applied multiple Angular testing APIs, and created realistic examples covering each major system of Angular.

If you need to write testable Angular code and want to take advantage of our experience of having already walked the path, this book will help you on your testing journey.

How this book is organized: a roadmap

The book has three parts that cover 11 chapters. Two appendixes include supplemental content:

  • Chapter 1 provides a gentle introduction to testing Angular applications. It offers background information on TypeScript and touches on the differences between unit testing and end-to-end testing. It also gives you an overview of the different tools—Jasmine, Karma, and Protractor—you’ll use throughout the book.

Part 1 covers the most common concepts that you’ll need to understand to write unit tests for Angular:

  • Chapter 2 will get your testing skills warmed up by writing basic tests. It discusses how to use key parts of the Jasmine framework, including beforeEach, afterEach, it, describe, and matcher functions. You’ll also learn how to test classes.
  • Chapter 3 discusses how to test the most fundamental concept in Angular: components. It introduces common testing classes and functions, and you’ll learn the differences between shallow and isolated tests.
  • Chapter 4 describes testing directives. You’ll learn how to test two types: attribute directives and structural directives.
  • Chapter 5 covers testing pipes. You’ll learn about the transform function, which is essential learning for writing tests for pipes. You’ll also learn about pure functions.
  • Chapter 6 discusses how to test services. The chapter covers how to test services that use the Angular HTTP class, how to test services using promises and RxJS observables, and how to use stubs to create isolated unit tests. The chapter also covers dependency injection with unit tests for services.
  • Chapter 7 goes deep into the subject of testing routing. Topics the chapter covers include configuring the router, testing components that use the router, and testing advanced router configurations.

Part 2 covers how to write end-to-end tests with Protractor:

  • Chapter 8 covers how to get started with Protractor. You’ll learn about how Protractor works, how to write your first Protractor tests, how to interact with elements, how to interact with a list of elements, and how to organize the tests with page objects.
  • Chapter 9 discusses timeouts. It goes into detail about understanding the causes of timeout errors in Protractor and how to avoid them, waiting for specific changes in your app, and understanding flakiness with Protractor and how to eliminate it.
  • Chapter 10 dives into advanced Protractor topics, like configuration files, screenshot testing, and debugging tests.

Part 3 is about continuous integration:

  • Chapter 11 demonstrates how to set up a continuous integration server that will automatically run all the tests you’ve been writing. Doing so will help you find bugs as soon as possible.

Appendix A covers setting up the sample project, and appendix B includes additional resources for you to consider.

In general, you can read the book from front to back, or you can pick and choose which chapters you want to read. Most chapters use the sample app, which you can install using appendix A, so you may want to get that set up before skipping around the book.

About the code

This book contains many examples of source code, both in numbered listings and inline with normal text. In both cases, this code is formatted in a fixed-width font like this to separate it from ordinary text. Sometimes code is also in bold to highlight when it has changed from previous steps in the chapter, such as when a new feature adds to an existing line of code.

In many cases, we’ve reformatted the original source code; we’ve added line breaks and reworked indentation to accommodate the available page space in the book. In rare cases, even this wasn’t enough, and listings include line-continuation markers (➥). Additionally, we’ve often removed comments in the source code from the listings when the code is described in the text, but code annotations accompany many of the listings to highlight important concepts.

You can find the accompanying code for the book on the book’s webpage at manning.com (www.manning.com/books/testing-angular-applications) and also on GitHub at http://mng.bz/z22f. To execute the code, you need to have Node.js version 6.9.0 or higher and npm version 3 or higher. You can use a Windows, Mac, or Linux machine. We wrote the code for this book on a Mac, so your experience may vary slightly. You can find installation instructions in appendix A.

Book forum

Purchase of Testing Angular Applications includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and from other users. To access the forum, go to https://forums.manning.com/forums/testing-angular-applications. You can also learn more about Manning's forums and the rules of conduct at https://forums.manning.com/forums/about.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions lest their interest stray! The forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.132.223