A controller relies on a service. We have to make sure that the integration works. We will write unit and integration tests for it.
- [Instructor] In the previous video,…we created the select pizza controller,…and set up the initial user interface of our app…that lets the user select a pizza,…and then click place order.…In this video, we're going to hook up…the place order button to a service.…In real-world AngularJS apps,…you will typically write controllers…that depend on one or more services.…In order to test the controller,…we also have to text the service,…or at least we have to make sure the controller is…calling the right functions in the service.…We use mocks to be able to test controllers…that depend on services.…
Open the file, app, script,…services, order service dot JS.…Now, let's define our service.…This service is going to be used for placing orders…using an ajax call to a rest API.…To keep things simple, we will not be…implementing the ajax call right now,…but we will need the Q module for creating promises.…Our factory will have a dependency on Q,…the promise module.…
AngularJS will inject this dependency when we run the tests,…
AngularJS offers the perfect balance between layout and code, making the framework a favorite of developers around the world. But what you might not know is that Angular also provides an outstanding infrastructure for testing, for developing bug-free and easily maintainable applications. Learning AngularJS Testing helps you to understand the different aspects involved in testing Angular components, including controllers and directives, with the help of a practical pizza-ordering application.
Author Rudolf Olah starts by installing and initializing various helpful testing tools, such as Karma, Jasmine, and Grunt. Then he creates controllers for ordering the pizza and reviewing the order, and tests them with and without dependencies. Chapter 3 shows how to create accordion directives for the application, unit test them, and resolve the errors if these tests fail. Rudolf also goes through testing of the navigation between two controllers with the help of End2End testing. Finally, learn how to modify services to use the $resource module and interact with REST API web services, as well as unit test them with the help of mocks and spies. Rudolf also shows how to create and test directives and controllers that fetch information from the service and display it.
- Configuring Angular, Grunt, Karma, and Jasmine for testing
- Testing controllers
- Testing directives
- Inspecting the navigation between components with End2End testing
- Creating REST API services and unit testing them to make your app compelling and user friendly