SlideShare a Scribd company logo
Hazem Saleh
§ JavaScript Testing Challenges.
§ Picking your JavaScript Unit Testing Framework.
§ Requirements of developing a clean unit test.
§ Jasmine Overview.
§ Basic Demo.
§ Use Case: AngularJS 5.x and Jasmine.
§ Use Case Demo-1.
§ Use Case Demo-2.
§ Conclusion.
Slow
Requires a lot of time to test on all the browsers.
JavaScript code that works on a browser X does not mean that it will work on browserY.
Inflexible
Supporting a new browser on an existing system means allocating a new budget:
• For testing this system on the new browser.
• For fixing newly discovered problems on the new browser.
JavaScript Unit Testing Tool
Executable across
browsers (Automated
preferred)
Fast to execute
Easy to setup Integrated
Easy to configure
Provides a good testing
mechanism for
Asynchronous code
Every test function should contain 10 lines of code or
less.
Every test function should have a proper name.
Every test function should have a single responsibility.
A unit test should test a single component at a time,
mocking all of its dependent components.
§Jasmine is a powerful JavaScript unit testing
framework.
§Jasmine describes its tests in a simple natural
language.
§Jasmine tests can be read by non-programmers.
§Jasmine provides a clean mechanism for testing
synchronous and asynchronous code.
Sample Jasmine Test
describe("A sample suite", function() {
it("contains a spec with an expectation", function() {
expect(true).toEqual(true);
});
});
Main Jasmine Constructs
TestSuite begins with a call to describe().
TestCase “or spec” begins with a call to it().
TestCase can contain one or more matcher(s).
Main Matchers
expect(x).toEqual(y)
expect(x).toBeTruthy()
expect(x).toBeFalsy()
expect(x).toBeLessThan(y)
expect(x).toBeGreaterThan(y)
expect(x).toMatch(pattern)
expect(x).toBe[Un]Defined()
expect(x).toBeNull()
expect(x).toContain(y)
expect(x).toWhatEver(Y)
“custom matcher”
beforeEach and afterEach example
JavaScript Unit Testing with an Angular 5.x Use Case 101
§AngularJS 5.x is a powerful UI MVW framework for
building client applications.
§TypeScript is one of the powerful options to be used
with AngularJS.
§Fortunately, Jasmine is compatible with TypeScript
and can be used seamlessly with AngularJS 5.x.
§The Angular Test Bed (ATB) is a higher level Angular
Only testing framework that allows us to easily test
behaviours that depend on the Angular Framework.
§ATB is fully integrated with Jasmine and Karma.
§ATB facilitates the following for testing:
§ AngularJs component creation.
§ Handling IoC (Dependency Injection).
§ Handling Async behavior.
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {LoginComponent} from './login.component';
import {AuthService} from "./auth.service";
describe('Component: Login', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [LoginComponent],
providers: [AuthService]
});
});
});
Project URL:
https://github.com/hazems/angularjs5-jasmine-demo
Project URL:
https://github.com/hazems/angularjs5-jasmine-demo/tree/navigation_test
§Testing JavaScript/TypeScript code is important for
increasing the quality of every application.
§Unit tests minimize the number of all kind of
defects, whether they are component-related or
regression related.
§Jasmine is a powerful unit testing framework which
can fit perfectly with almost every JavaScript
application.

More Related Content

PDF
Quick tour to front end unit testing using jasmine
PDF
Painless JavaScript Testing with Jest
PDF
JavaScript TDD with Jasmine and Karma
PDF
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
PDF
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
PDF
Advanced Jasmine - Front-End JavaScript Unit Testing
PDF
Angular testing
PDF
AngularJS Unit Testing w/Karma and Jasmine
Quick tour to front end unit testing using jasmine
Painless JavaScript Testing with Jest
JavaScript TDD with Jasmine and Karma
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
Advanced Jasmine - Front-End JavaScript Unit Testing
Angular testing
AngularJS Unit Testing w/Karma and Jasmine

What's hot (20)

ODP
Unit Testing and Coverage for AngularJS
PDF
Javascript tdd byandreapaciolla
PDF
Unit Testing with Jest
PPTX
Apex Testing and Best Practices
PPTX
Testing React Applications
PDF
Client side unit tests - using jasmine & karma
PDF
Сергей Больщиков "Protractor Tips & Tricks"
PPTX
Unit testing in JavaScript with Jasmine and Karma
PDF
Testing javascript in the frontend
PPTX
Angular Unit Testing
ODP
Angular JS Unit Testing - Overview
PDF
Adventures In JavaScript Testing
ODP
Jquery- One slide completing all JQuery
PDF
Testing JavaScript Applications
PPTX
JavaScript Coding Guidelines
PPTX
Test driven development with react
PDF
Quick Tour to Front-End Unit Testing Using Jasmine
PDF
Understanding JavaScript Testing
PDF
Intro to Unit Testing in AngularJS
PDF
Unit tests in node.js
Unit Testing and Coverage for AngularJS
Javascript tdd byandreapaciolla
Unit Testing with Jest
Apex Testing and Best Practices
Testing React Applications
Client side unit tests - using jasmine & karma
Сергей Больщиков "Protractor Tips & Tricks"
Unit testing in JavaScript with Jasmine and Karma
Testing javascript in the frontend
Angular Unit Testing
Angular JS Unit Testing - Overview
Adventures In JavaScript Testing
Jquery- One slide completing all JQuery
Testing JavaScript Applications
JavaScript Coding Guidelines
Test driven development with react
Quick Tour to Front-End Unit Testing Using Jasmine
Understanding JavaScript Testing
Intro to Unit Testing in AngularJS
Unit tests in node.js
Ad

Similar to JavaScript Unit Testing with an Angular 5.x Use Case 101 (20)

PDF
Efficient JavaScript Unit Testing, March 2013
PDF
Efficient JavaScript Unit Testing, JavaOne China 2013
PDF
Efficient JavaScript Unit Testing, May 2012
PDF
[FullStack NYC 2019] Effective Unit Tests for JavaScript
PPTX
Understanding JavaScript Testing
PPTX
PDF
Web UI test automation instruments
PDF
We Are All Testers Now: The Testing Pyramid and Front-End Development
PDF
Describe's Full of It's
PDF
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
PPTX
Testing And Mxunit In ColdFusion
PDF
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
PDF
Javascript-heavy Salesforce Applications
PDF
Front end unit testing using jasmine
PPTX
Angular Unit Testing
PDF
Token Testing Slides
ODP
Good Practices On Test Automation
PPTX
Junit_.pptx
PDF
Testing akka-actors
PPTX
introduction to java scriptsfor sym.pptx
Efficient JavaScript Unit Testing, March 2013
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, May 2012
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Understanding JavaScript Testing
Web UI test automation instruments
We Are All Testers Now: The Testing Pyramid and Front-End Development
Describe's Full of It's
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
Testing And Mxunit In ColdFusion
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
Javascript-heavy Salesforce Applications
Front end unit testing using jasmine
Angular Unit Testing
Token Testing Slides
Good Practices On Test Automation
Junit_.pptx
Testing akka-actors
introduction to java scriptsfor sym.pptx
Ad

More from Hazem Saleh (14)

PDF
Mockito 2.x Migration - Droidcon UK 2018
PPTX
[AnDevCon 2016] Mutation Testing for Android
PPTX
[ApacheCon 2016] Advanced Apache Cordova
PPTX
[Devoxx Morocco 2015] Apache Cordova In Action
PPTX
Apache Cordova In Action
PPTX
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
PPTX
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
PDF
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
PDF
Dojo >= 1.7 Kickstart
PDF
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
PDF
JSF Mashups in Action
PDF
JavaScript tools
PDF
[JavaOne 2010] Abstract Mashups for Enterprise Java
PDF
GMaps4JSF
Mockito 2.x Migration - Droidcon UK 2018
[AnDevCon 2016] Mutation Testing for Android
[ApacheCon 2016] Advanced Apache Cordova
[Devoxx Morocco 2015] Apache Cordova In Action
Apache Cordova In Action
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
Dojo >= 1.7 Kickstart
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
JSF Mashups in Action
JavaScript tools
[JavaOne 2010] Abstract Mashups for Enterprise Java
GMaps4JSF

Recently uploaded (20)

PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
Lecture Notes Electrical Wiring System Components
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
PPT on Performance Review to get promotions
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Sustainable Sites - Green Building Construction
PPT
introduction to datamining and warehousing
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
Digital Logic Computer Design lecture notes
PPTX
Current and future trends in Computer Vision.pptx
PPTX
Safety Seminar civil to be ensured for safe working.
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Foundation to blockchain - A guide to Blockchain Tech
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Lecture Notes Electrical Wiring System Components
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
PPT on Performance Review to get promotions
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Sustainable Sites - Green Building Construction
introduction to datamining and warehousing
Operating System & Kernel Study Guide-1 - converted.pdf
bas. eng. economics group 4 presentation 1.pptx
Mechanical Engineering MATERIALS Selection
Digital Logic Computer Design lecture notes
Current and future trends in Computer Vision.pptx
Safety Seminar civil to be ensured for safe working.

JavaScript Unit Testing with an Angular 5.x Use Case 101