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

What's hot (20)

ODP
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
PDF
Javascript tdd byandreapaciolla
Andrea Paciolla
 
PDF
Unit Testing with Jest
Maayan Glikser
 
PPTX
Apex Testing and Best Practices
Jitendra Zaa
 
PPTX
Testing React Applications
stbaechler
 
PDF
Client side unit tests - using jasmine & karma
Adam Klein
 
PDF
Сергей Больщиков "Protractor Tips & Tricks"
Fwdays
 
PPTX
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
PDF
Testing javascript in the frontend
Frederic CABASSUT
 
PPTX
Angular Unit Testing
Avi Engelshtein
 
ODP
Angular JS Unit Testing - Overview
Thirumal Sakthivel
 
PDF
Adventures In JavaScript Testing
Thomas Fuchs
 
ODP
Jquery- One slide completing all JQuery
Knoldus Inc.
 
PDF
Testing JavaScript Applications
The Rolling Scopes
 
PPTX
JavaScript Coding Guidelines
Oleksii Prohonnyi
 
PPTX
Test driven development with react
Leon Bezuidenhout
 
PDF
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
PDF
Understanding JavaScript Testing
jeresig
 
PDF
Intro to Unit Testing in AngularJS
Jim Lynch
 
PDF
Unit tests in node.js
Rotem Tamir
 
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
Javascript tdd byandreapaciolla
Andrea Paciolla
 
Unit Testing with Jest
Maayan Glikser
 
Apex Testing and Best Practices
Jitendra Zaa
 
Testing React Applications
stbaechler
 
Client side unit tests - using jasmine & karma
Adam Klein
 
Сергей Больщиков "Protractor Tips & Tricks"
Fwdays
 
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Testing javascript in the frontend
Frederic CABASSUT
 
Angular Unit Testing
Avi Engelshtein
 
Angular JS Unit Testing - Overview
Thirumal Sakthivel
 
Adventures In JavaScript Testing
Thomas Fuchs
 
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Testing JavaScript Applications
The Rolling Scopes
 
JavaScript Coding Guidelines
Oleksii Prohonnyi
 
Test driven development with react
Leon Bezuidenhout
 
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
Understanding JavaScript Testing
jeresig
 
Intro to Unit Testing in AngularJS
Jim Lynch
 
Unit tests in node.js
Rotem Tamir
 

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

PPTX
Angular Unit testing.pptx
RiyaBangera
 
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
PPTX
Angular Unit Testing
Alessandro Giorgetti
 
PDF
Angular Application Testing
Troy Miles
 
PDF
Unit Testing in Angular
Knoldus Inc.
 
PDF
Angular Testing
Kourosh Sajjadi
 
PPTX
jasmine
Asanka Indrajith
 
PPT
Testing in AngularJS
Peter Drinnan
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
PDF
An Introduction To Testing In AngularJS Applications
Rohan Chandane
 
PDF
Front end unit testing using jasmine
Gil Fink
 
PDF
Angularjs Test Driven Development (TDD)
Anis Bouhachem Djer
 
PPTX
Slaven tomac unit testing in angular js
Slaven Tomac
 
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
PDF
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Javascript Unit Testing Tools
PixelCrayons
 
PPTX
Unit testing using jasmine in Javascript
Deepak More
 
PPTX
Javascript Testing with Jasmine 101
Roy Yu
 
PDF
Unit-testing and E2E testing in JS
Michael Haberman
 
Angular Unit testing.pptx
RiyaBangera
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
Angular Unit Testing
Alessandro Giorgetti
 
Angular Application Testing
Troy Miles
 
Unit Testing in Angular
Knoldus Inc.
 
Angular Testing
Kourosh Sajjadi
 
Testing in AngularJS
Peter Drinnan
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
An Introduction To Testing In AngularJS Applications
Rohan Chandane
 
Front end unit testing using jasmine
Gil Fink
 
Angularjs Test Driven Development (TDD)
Anis Bouhachem Djer
 
Slaven tomac unit testing in angular js
Slaven Tomac
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Javascript Unit Testing Tools
PixelCrayons
 
Unit testing using jasmine in Javascript
Deepak More
 
Javascript Testing with Jasmine 101
Roy Yu
 
Unit-testing and E2E testing in JS
Michael Haberman
 
Ad

More from Hazem Saleh (18)

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

Recently uploaded (20)

PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PPT
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
PDF
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 

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