ebook img

AngularJS Test-driven Development PDF

288 Pages·2015·13.53 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview AngularJS Test-driven Development

AngularJS Test-driven Development Table of Contents AngularJS Test-driven Development Credits About the Author About the Reviewers www.PacktPub.com Support files, eBooks, discount offers, and more Why subscribe? Free access for Packt account holders Preface What this book covers Who this book is for Conventions Reader feedback Customer support Downloading the example code Errata Piracy Questions 1. Introduction to Test-driven Development An overview of TDD Fundamentals of TDD Measuring success Breaking down the steps Measure twice cut once Diving in Setting up the test Creating a development to-do list Test first Making it run Making it better Testing techniques Testing with a framework Testing doubles with Jasmine spies Stubbing a return value Testing arguments Refactoring Building with a builder Self-test questions Summary 2. The Karma Way JavaScript testing tools Karma Protractor JavaScript testing frameworks Jasmine Selenium Mocha Birth of Karma The Karma difference Importance of combining Karma with AngularJS Installing Karma Installation prerequisites Configuring Karma Customizing Karma’s configuration Confirming Karma’s installation and configuration Common installation/configuration issues Testing with Karma Confirming the Karma installation Using Karma with AngularJS Getting AngularJS Bower Bower installation Installing AngularJS Installing Angular mocks Initializing Karma Testing with AngularJS and Karma A development to-do list Testing a list of items Test first Assemble, Act, and Assert (3 A’s) Make it run Make it better Adding a function to the controller Test first Assemble, Act, and Assert (3 A’s) Make it run Make it better Self-test questions Summary 3. End-to-end Testing with Protractor An overview of Protractor Origins of Protractor End of life The birth of Protractor Life without Protractor Protractor installation Installation prerequisites Installing Protractor Installing WebDriver for Chrome Customizing configuration Confirming installation and configuration Common installation/configuration issues Hello Protractor TDD end-to-end The pre-setup The setup Test first Installing the test web server Configuring Protractor Getting down to business Specification The development to-do list Test first Assemble, Act, Assert (3 A’s) Running the test Make it run Make it better Cleaning up the gaps Async magic Loading a page before test execution Assertion on elements that get loaded in promises TDD with Protractor Self-test questions Summary 4. The First Step Preparing the application’s specification Setting up the project Setting up the directory Setting up Protractor Setting up Karma Setting up http-server Top-down or bottom-up approach Testing a controller A simple controller test setup Initializing the scope Bring on the comments Test first Assemble Act Assert Make it run Adding the module Adding the input Controller Make it pass Make it better Implementing the Submit button Configuring Karma Test first Assemble Act Assert Make it run Make it better Back up the test chain Bind the input Onwards and upwards Test first Assemble Act Assert Make it run Fixing the unit tests Make it better Coupling of the test Self-test questions Summary 5. Flip Flop Fundamentals Protractor locators CSS locators Button and link locators Angular locators URL location references Creating a new project Setting up headless browser testing for Karma Preconfiguration Configuration Walk-through of Angular routes Setting up AngularJS routes Defining directions Configuring ngRoute Defining the route controllers Defining the route views Assembling the flip flop test Making the views flip Asserting a flip Making flip flop run Making flip flop better Searching the TDD way Deciding on the approach Walk-through of search query The search query test The search query HTML page The search application Show me some results! Creating the search result routes Testing the search results Assembling the search result test Selecting a search result Confirming a search result Making the search result test run Creating a location-aware test Making the search result better Confirming the route ID Setting up the route ID unit test Confirming the ID Making the route parameter’s test run Self-test questions Summary 6. Telling the World Before the plunge Karma configuration File watching Using a bottom-up approach Services Publishing and subscribing messages Emitting Testing emit Testing broadcast Testing broadcast Publishing and subscribing – the good and bad The good Communicating through events Reducing coupling Harnessing the power of events The plan Rebranding Seeing recently viewed items Test first Assembling SearchController Selecting a product Expecting events to be published Making the search controller run Recently viewed unit test Test first Assembling RecentlyViewedController Invoking a recently viewed item Confirming RecentlyViewedController Making RecentlyViewedController run End-to-end testing Test first Assembling the recently viewed end-to-end test Selecting a search result Confirming recently viewed items Making the recentlyViewedItems test pass Making recently viewed items better Creating a product cart Publisher test first Assembling searchDetailController Invoking the saving of a product Confirming the save event Making the saveProduct test pass Test for the subscriber first Assembling the product cart test Invoking a saved cart event

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.