We require a custom user interface component. So, we will create a directive.
- [Instructor] In this section,…we're going to be covering…how to create and test a directive using unit tests…and how a directive becomes part of End2End testing.…In this first video, we're going to be creating…an accordion directive.…An accordion user interface displays panels…that can be switched between…by clicking on a panel title.…Before we start writing our accordion directive,…we need to find out how we want to use it.…We open the select-pizza template,…and we pretend that the accordion directive already exists.…
We create a panel with the title "Special Deal"…that contains some text.…The h2 element contains the accordion panel title.…The div contains the body of the accordion panel.…We create a second panel titled "25% off vegetarian pizza."…The title is in the h2 element,…and the body of this panel is in the div.…Now, to start writing our accordion directive.…First, we create the directory…where directives will be stored.…
Then, we open accordionDirective.js…and start writing our directive.…First, we make the directive…
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