We need a useful directive. We will create a directive that is hooked up to a service.
- View Offline
- [Instructor] Welcome to video 4.3,…Displaying Information with a Directive from a Service.…In the previous two videos,…we implemented an order service and created…a fake API server for testing.…In this video, we will be creating a directive…that uses the service and testing it…with unit tests and end2end tests.…We want to be able to create directives…that rely on services and be able to test them…with unit tests and end2end tests…so that we can be sure that it works correctly.…In our Pizza Store web app,…we're going to display the status of the order,…as it's happening.…
Since we're practicing test-driven development,…we're going to begin by running a unit test…for this directive.…Open the file, Order Status Directive spec…in the spec/unit directory and let's start running…the unit test.…First, we need to mark out the service.…We need to store our reference to the order service…and then create a fake implementation…of the Get Order Status method.…On the first call to the fake method,…we will return a promise with the status message…
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