Implement the best practices to improve your AngularJS applications using test-driven developmentAbout This BookLearn about TDD techniques, the TDD lifecycle, and its power through clear examples to enhance your Angular applicationsIntegrate AngularJS testing using Karma and Protractor to perform JavaScript unit testsA practical guide filled with examples that focus on a wide range of testing techniques with AngularJS componentsWho This Book Is ForThis book is for developers who want to learn about AngularJS development by applying testing techniques. You are assumed to have a basic knowledge and understanding of HTML, JavaScript, and AngularJS.
What You Will LearnImplement unit and end-to-end testing with Karma and ProtractorUnderstand the workings of the file auto-watch feature and headless browser testing with KarmaDevelop AngularJS controllers, services, and other components using the TDD approachImplement the testing techniques with mocks, broadcast events, and asynchronous behaviorIntegrate REST-based services and APIs into an application to extract dataAutomate Karma unit tests with Travis CIGet to know about TDD techniques, the TDD life cycle, and its power through clear examples to enhance your AngularJS applicationsIn DetailStarting with reviewing the test-driven development (TDD) life cycle, you will learn how Karma and Protractor make your life easier while running JavaScript unit tests. You will learn how Protractor is different from Selenium and how to test it entirely. This book is a walk-through to using TDD to build an AngularJS application containing a controller, model, and scope.
Building on the initial foundational aspects, you will expand to include testing for multiple controllers, partial views, location references, CSS, and the HTML element. In addition, you will explore using a headless browser with Karma. You will also configure Karma file watching to automate testing and tackle components of AngularJS (controller, service, model, and broadcasting) using TDD. At the end of this book, you will extend explore how to pull data using an external API, setting up and configuring Protractor to use a standalone Selenium server, and setting up Travis CI and Karma to test your application.
This book is a complete guide to testing techniques using Karma for unit testing and performing end-to-end testing with Protractor.
An excellent end-to-end walk-through of an Angular workflow where testing is as natural and unobtrusive as possible. Unit testing with Jasmine/Karma and end-to-end testing with Protractor are thoroughly covered (although the author by no means exhausts the Jasmine and Protractor APIs), and he makes a very strong case for true test-driven development.
Though I've been personally working with Jasmine/Karma for awhile, I've never learned to use Protractor and I'm glad this book covered it. The online documentation and available tutorials on Protractor is a bit spotty and it's been hard to try and self-teach, so that lead me to search for some good books. Amos Haviv's "MEAN Web Development" doesn't cover much of Protractor, and really neither have Adam Freeman or any of Brad Dayley's Angular books, but the need for end-to-end testings is certainly there.
Reading this book I realized how I was pushing my unit tests to do what could be more easily done in Protractor, and as a result of the effort involved in writing those kinds of jQuery-heavy DOM inspecting tests, I was thereafter reluctant to keep my unit tests in sync whenever I made coding changes. The better solution would have been (in hindsight) to learn how to use Protractor, scale back on the jQuery usage in my unit tests, and limit the scope of my true unit tests to where they more naturally fall in place.
I am not sure I'll be able to personally adopt a full test-driven development workflow, but we'll see over time if the impression left on my by this book will set in. Test-driven development is a hard mindset to adopt as it takes away from the ingrained workflow that most of us have had for our entire careers, but if it can be done in any particular language it would probably be least obtrusive in a dynamic language like JavaScript or Python.
One word of caution with this author's style is he tends to introduce features in code before fully defining them, but stick with it because he'll do so later. It might frustrate you at first as you leaf back through the book to see if you missed something earlier, but he will explain in-depth later (sometimes in a later chapter even). In retrospect I think I prefer this to the more standard pattern of a dictionary's worth of definitions and explanations before you get to see it in action. And to his credit, the author understands the value of repetition in driving home new concepts as you'll be exposed to new concepts several times and sometimes with a few different looks at it before moving on to the next concept. So this is definitely the type of book where you can learn new concepts instead of just wetting your appetite enough to be confused and then end up searching the web for the API docs.