We need to make sure that the UI works automatically. We will write a unit test for it.
- View Offline
- [Instructor] In the previous video,…we created an accordion directive.…In this video, we will be writing unit tests…to prove that the accordion directive works properly.…Unit testing an interface component can be difficult,…but with Angular and Jasmine we're able to do so easily.…Angular JS is specifically designed to make all components,…including user interface components, testable.…It does this through the use of dependency injection,…which makes it possible to style or mock out whole modules…that your code depends on.…The separation of concerns between the…controllers and directives in Angular JS…is the reason we can test the directive properly…and in isolation.…
Let's begin by creating a new test specification…for the accordion.…Open the file accordionDirectiveSpec.JS…in the spec\unit directory…and let's begin with defining the HTML…that we'll use and display our accordion directive.…It will contain two panels, which is enough for us to test.…Then we declare the scope variable,…which would store a reference to the root scope.…
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