0% found this document useful (0 votes)
26 views

Angular Testing: Jogesh K. Muppala

This document discusses testing Angular applications. It explains that Angular was designed to facilitate testing with features like modularity and dependency injection. It introduces test-driven development, where tests are written before code to define desired functionality. It also covers unit testing, isolating units from dependencies using mocks, and frameworks like Jasmine and Karma that are used for Angular testing. The Angular testing utilities like TestBed help set up a test environment and components under test.

Uploaded by

vikram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Angular Testing: Jogesh K. Muppala

This document discusses testing Angular applications. It explains that Angular was designed to facilitate testing with features like modularity and dependency injection. It introduces test-driven development, where tests are written before code to define desired functionality. It also covers unit testing, isolating units from dependencies using mocks, and frameworks like Jasmine and Karma that are used for Angular testing. The Angular testing utilities like TestBed help set up a test environment and components under test.

Uploaded by

vikram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Angular

Testing

Jogesh K. Muppala
Testing Angular Applications
• Angular was built from the ground-up to
facilitate testing
– Modular implementation with components,
services and providers etc.
– Dependency injection

2
Test-Driven Development
• Write an automated test case defining the
desired functionality
• Write application code to pass the test
• Refactor the code to meet coding standards

https://en.wikipedia.org/wiki/Test-driven_development

3
Unit Testing
• Testing individual units of code
– Restricted to verifying if the component’s logic is
implemented correctly
• Isolating the unit under test from other dependencies
is important
– Dependency injection enables us to inject mock
dependencies
– Clear separation in Angular between the DOM and logic

4
Jasmine
• Behavior driven development framework for
JavaScript
– Adopted to test Angular applications
– Use “describe” function to group our tests
– Use “it” function to define individual tests

5
Karma
• JavaScript based command line tool (NodeJS
application)
– Spawns a web server to load your application’s
source code
– Executes your tests in the browser

6
Angular Testing Utilities
• Create a test environment for the Angular application code under test
• Use them to condition and control parts of the application as they
interact within the Angular environment
• TestBed creates an Angular testing Module (@NgModule) to enable
testing of components
– TestBed.createComponent creates an instance of the component under test
– Gives access to ComponentFixture, a handle on the test environment
surrounding the created component.
– The fixture provides access to the component instance itself and to
the DebugElement, which is a handle on the component's DOM element.

You might also like