SlideShare a Scribd company logo
Javascript Testing
Tools of the trade
Juanma Orta
Front/Back end developer
at Ulabox.com
@JuanmaOrta
The Tools
Jasmine
The testing framework
Karma
The test runner
ĥ
The headless browser
Protractor
The E2E framework
Jasmine
Suite and spec based testing framework. Allows dependency mocking and
custom matchers.
The suite
(function (rps) {
‘use strict’;
describe(‘when playing rock-paper-scissors’, function() {
});
}(RockPaperScissors)); // the module under test
Setup and tear down
describe(‘when playing rock-paper-scissors’, function() {
var foo = ‘’;
beforeEach(function() {
foo = ‘bar’;
});
afterEach(function() {
foo = ‘’;
});
});
The specification (spec)
describe(‘when playing rock-paper-scissors’, function() {
it(‘will show that rock wins scissors’, function() {
var result = rps.whoWins(‘rock’, ‘scissors’);
expect(result).toEqual(1);
})
});
“Suites and specs are just plain JS functions”
- From an expert
Mocking dependencies
it(‘will show that rock wins scissors’, function() {
var choice = ‘rock’;
spyOn(rps, ‘validate’).and.callFake(function() { // Jasmine 2.0 syntax
return choice;
});
spyOn(rps, ‘whoWins’).andCallFake(function() { // Jasmine 1.x syntax
$(document).trigger(‘score:user1’);
});
Matchers
Common matchers
expect(true).toBe(true);
expect(true).not.toBe(fase);
.toEqual
...
jQuery matchers
Using jasmine-jquery module
expect($(‘#info’)).toBeVisible();
expect($(‘#info’)).toHaveClass();
expect($(‘#myField’)).toHaveValue(‘123’);
Custom Matchers
var customMatchers = {
toBeActive: function() {
return {
compare: function(item) {
...
}
}
}
};
beforeEach(function() {
jasmine.addMatchers(customMatchers);
});
expect($(‘#element’)).toBeActive();
expect($(‘#element’)).not.toBeActive();
Enter the Karma
“Karma is essentially a tool which spawns a web server that executes source code against test code for each of the
browsers connected. The results for each test against each browser are examined and displayed via the command line to
the developer such that they can see which browsers and tests passed or failed.”
$ karma start
The browsers
● Google Chrome
● Mozilla Firefox
● Safari (only on OS X)
● Internet Explorer (yes, IE too, but only on Win machines)
and
● Phantom JS -> the headless one
Protractor: End to end testing (e2e)
Designed basically for AngularJS e2e testing,
runs tests in a real browser.
Simulates user interactions
Can use any test framework,
but works smoothly with Jasmine
It can also be used to test
non-angularjs applications
Example protractor test
beforeEach(function () {
browser.ignoreSynchronization = true;
browser.get(‘http://localhost:9000’);
});
it(‘should show …’, function() {
element(by.id(‘myChoice’))
.sendKeys(‘stone’);
element(by.css(‘.btn’)).click();
alert = element.all(by.css(‘.alert’))
expect(alert.count()).toBe(1);
});
Resources
The repo of this tests and exercises:
https://github.com/juanmaorta/rockpaperscissors.git
Jasmine: http://jasmine.github.io/
Karma: http://karma-runner.github.io/0.13/index.html
Protractor: https://angular.github.io/protractor/#/
Thanks!
Contact me:
Juanma Orta
Ulabox.com
juanma.orta@ulabox.com
@JuanmaOrta

More Related Content

KEY
Testing JS with Jasmine
PPTX
Jasmine framework
PPTX
Boost statechart library
PDF
Intro to testing Javascript with jasmine
PDF
Quick tour to front end unit testing using jasmine
PPTX
Security testing of YUI powered applications
PDF
Unit Testing JavaScript Applications
PPTX
Unit testing in JavaScript with Jasmine and Karma
Testing JS with Jasmine
Jasmine framework
Boost statechart library
Intro to testing Javascript with jasmine
Quick tour to front end unit testing using jasmine
Security testing of YUI powered applications
Unit Testing JavaScript Applications
Unit testing in JavaScript with Jasmine and Karma

What's hot (20)

PDF
AngularJS Unit Testing w/Karma and Jasmine
PDF
Angular testing
PPTX
Unit testing on mobile apps
PPTX
Unit testing JavaScript: Jasmine & karma intro
PPTX
Protractor Tutorial Quality in Agile 2015
PDF
Angularjs - Unit testing introduction
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
ODP
Angular JS Unit Testing - Overview
PDF
Intro to Unit Testing in AngularJS
PDF
Javascript tdd byandreapaciolla
PDF
Test-Driven Development of AngularJS Applications
PPTX
Testing frontends with nightwatch & saucelabs
PPT
Testing in AngularJS
PDF
Introduction to jvm with asm
PPTX
Angular Unit Testing
PPTX
Angularjs Performance
PDF
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
PPTX
Testing angular js
PPTX
Unit tests and mocks
PDF
AngularJS - Overcoming performance issues. Limits.
AngularJS Unit Testing w/Karma and Jasmine
Angular testing
Unit testing on mobile apps
Unit testing JavaScript: Jasmine & karma intro
Protractor Tutorial Quality in Agile 2015
Angularjs - Unit testing introduction
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Angular JS Unit Testing - Overview
Intro to Unit Testing in AngularJS
Javascript tdd byandreapaciolla
Test-Driven Development of AngularJS Applications
Testing frontends with nightwatch & saucelabs
Testing in AngularJS
Introduction to jvm with asm
Angular Unit Testing
Angularjs Performance
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Testing angular js
Unit tests and mocks
AngularJS - Overcoming performance issues. Limits.
Ad

Viewers also liked (20)

PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
PDF
[Js hcm] Java script- Testing the awesome
PDF
Testing your javascript code with jasmine
PDF
JavaScript Unit Testing with Jasmine
PDF
GruntJS + Wordpress
PDF
Grunt js and WordPress
PPT
An Introduction to AngularJs Unittesting
PDF
Mastering Grunt
PDF
Angular js, Yeomon & Grunt
ODP
Wrangling the WordPress Template Hierarchy Like a Boss
PPTX
WordPress Theme Development Workflow with Node.js, Ruby, Sass, Bower and Grunt
PPTX
Metadata and me
PDF
A Quick and Dirty D3.js Tutorial
PPTX
Javascript Testing with Jasmine 101
PDF
The Developer Experience
PDF
Developer Experience to Testing
PDF
Testing javascript in the frontend
PDF
Unit Testing Lightning Components with Jasmine
PPTX
JavaScript Unit Testing
PDF
Come migliorare le performance di WordPress con il Visual Composer
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
[Js hcm] Java script- Testing the awesome
Testing your javascript code with jasmine
JavaScript Unit Testing with Jasmine
GruntJS + Wordpress
Grunt js and WordPress
An Introduction to AngularJs Unittesting
Mastering Grunt
Angular js, Yeomon & Grunt
Wrangling the WordPress Template Hierarchy Like a Boss
WordPress Theme Development Workflow with Node.js, Ruby, Sass, Bower and Grunt
Metadata and me
A Quick and Dirty D3.js Tutorial
Javascript Testing with Jasmine 101
The Developer Experience
Developer Experience to Testing
Testing javascript in the frontend
Unit Testing Lightning Components with Jasmine
JavaScript Unit Testing
Come migliorare le performance di WordPress con il Visual Composer
Ad

Similar to Javascript testing: tools of the trade (20)

PPTX
Protractor framework architecture with example
PPT
Automated javascript unit testing
PDF
CasperJs Enjoy Functional Testing
PPTX
Slaven tomac unit testing in angular js
PDF
Painless Javascript Unit Testing
PDF
Thomas Fuchs Presentation
ODP
Unit Testing and Coverage for AngularJS
PDF
Testing in JavaScript
PDF
Adventures In JavaScript Testing
PDF
Unit testing JavaScript using Mocha and Node
PDF
Node.js vs Play Framework (with Japanese subtitles)
PPTX
PDF
Playwright Test automation frameworktest
PDF
UI Testing Best Practices - An Expected Journey
PDF
Testing in JavaScript - August 2018 - WebElement Bardejov
PDF
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
PDF
Continuous Integration for front-end JavaScript
PPTX
A few good JavaScript development tools
PDF
PDF
Web UI test automation instruments
Protractor framework architecture with example
Automated javascript unit testing
CasperJs Enjoy Functional Testing
Slaven tomac unit testing in angular js
Painless Javascript Unit Testing
Thomas Fuchs Presentation
Unit Testing and Coverage for AngularJS
Testing in JavaScript
Adventures In JavaScript Testing
Unit testing JavaScript using Mocha and Node
Node.js vs Play Framework (with Japanese subtitles)
Playwright Test automation frameworktest
UI Testing Best Practices - An Expected Journey
Testing in JavaScript - August 2018 - WebElement Bardejov
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
Continuous Integration for front-end JavaScript
A few good JavaScript development tools
Web UI test automation instruments

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Transform Your Business with a Software ERP System
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
top salesforce developer skills in 2025.pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
Introduction to Artificial Intelligence
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Transform Your Business with a Software ERP System
Adobe Illustrator 28.6 Crack My Vision of Vector Design
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms II-SECS-1021-03
PTS Company Brochure 2025 (1).pdf.......
Softaken Excel to vCard Converter Software.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
CHAPTER 2 - PM Management and IT Context
VVF-Customer-Presentation2025-Ver1.9.pptx
top salesforce developer skills in 2025.pdf
ISO 45001 Occupational Health and Safety Management System
Introduction to Artificial Intelligence
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
ManageIQ - Sprint 268 Review - Slide Deck
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Wondershare Filmora 15 Crack With Activation Key [2025
Which alternative to Crystal Reports is best for small or large businesses.pdf

Javascript testing: tools of the trade