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)

PDF
Efficient JavaScript Unit Testing, March 2013
Hazem Saleh
 
PDF
Efficient JavaScript Unit Testing, JavaOne China 2013
Hazem Saleh
 
PDF
Efficient JavaScript Unit Testing, May 2012
Hazem Saleh
 
PDF
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Hazem Saleh
 
PPTX
Understanding JavaScript Testing
Kissy Team
 
PPTX
jasmine
Asanka Indrajith
 
PDF
Web UI test automation instruments
Artem Nagornyi
 
PDF
We Are All Testers Now: The Testing Pyramid and Front-End Development
All Things Open
 
PDF
Describe's Full of It's
Jim Lynch
 
PDF
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
Anup Singh
 
PPTX
Testing And Mxunit In ColdFusion
Denard Springle IV
 
PDF
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
GeeksLab Odessa
 
PDF
Javascript-heavy Salesforce Applications
Salesforce Developers
 
PDF
Front end unit testing using jasmine
Gil Fink
 
PPTX
Angular Unit Testing
Alessandro Giorgetti
 
PDF
Token Testing Slides
ericholscher
 
ODP
Good Practices On Test Automation
Gustavo Labbate Godoy
 
PPTX
Junit_.pptx
Suman Sourav
 
PDF
Testing akka-actors
Knoldus Inc.
 
PPTX
introduction to java scriptsfor sym.pptx
gayatridwahane
 
Efficient JavaScript Unit Testing, March 2013
Hazem Saleh
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Hazem Saleh
 
Efficient JavaScript Unit Testing, May 2012
Hazem Saleh
 
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Hazem Saleh
 
Understanding JavaScript Testing
Kissy Team
 
Web UI test automation instruments
Artem Nagornyi
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
All Things Open
 
Describe's Full of It's
Jim Lynch
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
Anup Singh
 
Testing And Mxunit In ColdFusion
Denard Springle IV
 
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
GeeksLab Odessa
 
Javascript-heavy Salesforce Applications
Salesforce Developers
 
Front end unit testing using jasmine
Gil Fink
 
Angular Unit Testing
Alessandro Giorgetti
 
Token Testing Slides
ericholscher
 
Good Practices On Test Automation
Gustavo Labbate Godoy
 
Junit_.pptx
Suman Sourav
 
Testing akka-actors
Knoldus Inc.
 
introduction to java scriptsfor sym.pptx
gayatridwahane
 
Ad

More from Hazem Saleh (14)

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
JSF Mashups in Action
Hazem Saleh
 
PDF
JavaScript tools
Hazem Saleh
 
PDF
[JavaOne 2010] Abstract Mashups for Enterprise Java
Hazem Saleh
 
PDF
GMaps4JSF
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
 
JSF Mashups in Action
Hazem Saleh
 
JavaScript tools
Hazem Saleh
 
[JavaOne 2010] Abstract Mashups for Enterprise Java
Hazem Saleh
 
GMaps4JSF
Hazem Saleh
 
Ad

Recently uploaded (20)

PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PPTX
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
Digital water marking system project report
Kamal Acharya
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PDF
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Digital water marking system project report
Kamal Acharya
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 

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