SlideShare a Scribd company logo
Client side testingClient side testing
Before we startBefore we start
Hebrew or English?
Don't wait for the "Questions?" slide
I'm skipping the "why test?" intro
YouYou
Adam Klein
CTO of 500Tech
meetup.com/AngularJS-IL
angular.co.il
hackademy.co.il
Among our clients:
- Wix
- Cellebrite
- eToro
- Autodesk
- ...
MeMe
JasmineJasmine
The most popular testing
framework
var Person = function(first, last) {
this.fullname = function() {
return first + ' ' + last;
}
}
describe ('Person', function() {
it('should return fullname correctly', function() {
var p = new Person('Adam', 'Klein');
expect(p.fullname()).toEqual('Adam Klein');
});
});
ExampleExample
It runs in the browserIt runs in the browser
+1 on credibility+1 on credibility
Let's see it in action
Debugging the testDebugging the test
chrome dev toolschrome dev tools
JasmineJasmine
What it is not:
It's not a framework for running tests
But karma is....
Is a test running framework
Makes the browser interaction seamless
Works with various testing frameworks, not just
jasmine
KarmaKarma
formerly testacular
renamed because it resembles....
Let's see it live
Run in severalRun in several
browsers at oncebrowsers at once
karma-firefox-launcher
karma-chrome-launcher
karma-phantomjs-launcher
Other cool stuffOther cool stuff
OSX reporter
Coverage
...
You might ask yourself, how the hell do IYou might ask yourself, how the hell do I
unit test this code:unit test this code:
<button onclick="addOne()">
Add one
</button>
<h1>0</h1>
function addOne() {
var count = $('h1');
var number = parseInt(count.text());
count.text(number + 1);
}
html
Javascript
Karma html2JS toKarma html2JS to
the rescuethe rescue
Load an html file in the current DOM
Test the javascript that interacts with it
Preparation
document.body.innerHTML = __html__['views/index.html'];
var button = $('button');
var h1 = $('h1');
it('should start with 0', function() {
expect(h1.text()).toEqual('0');
});
it('should add one', function() {
button.click();
expect(h1.text()).toEqual('1');
});
Test
AngularJSAngularJS
<div ng-controller="myController">
<button ng-click="addOne()">
Add one
</button>
<h1>{{count}}</h1>
</div>
function MyController($scope) {
$scope.count = 0;
$scope.addOne = function() {
$scope.count++;
}
}
AngularJSAngularJS
Controller
Handles view state
Makes data and functions accessible via $scope
Doesn't know DOM
View (template)
Data binding
Glue events
How the test will look likeHow the test will look like
it('should bind h1 to count', function() {
$scope.count = 10;
$scope.$apply();
expect(h1.text()).toEqual('10');
});
it('should call add one on button click', function() {
button.click();
expect($scope.addOne).toHaveBeenCalled();
});
What about system testsWhat about system tests
with Selenium you ask?with Selenium you ask?
Good question!!
Follow our twitter for my
coming presentation on how to
make maintainable, readable,
and fast system tests.....
Our mediaOur media
Our presentations
Cool libraries & services
Interesting blog posts
Courses & workshops
@500TechIL
500Tech on facebook
external serverexternal server
productsService = {
products: [],
create: function(product) {
var response = $.ajax(...);
if(response.success) {
this.products.push(product);
}
}
}
Easy to mockEasy to mock
serverApi
productsService
actual server
HTTP
Something like thisSomething like this
productsService = {
products: [],
create: function(product) {
var response = serverApi.createProduct(product);
if(response.success) {
this.products.push(product);
}
}
}
serverApi = {
createProduct: function(product) {
$.ajax(...);
}
}
Spy / Mock / Stub / FakeSpy / Mock / Stub / Fake
spyOnspyOn
var product = {name: 'product'};
spyOn(serverApi, 'createProduct').andReturn({success: true});
productsService.create(product);
expect(productsService.products).toEqual([product]);
Test the side effectTest the side effect
expect(serverApi.createProduct).
toHaveBeenCalledWith(product);
Credibility alert!Credibility alert!
Test might pass but code will fail
The spies are the contract with the server
Keep in TouchKeep in Touch
@500TechIL
blog.500tech.com
meetup.com/angularjs-il
meetup.com/hackademy
hackademy.co.il

More Related Content

PPTX
JavaScript Operators
PDF
2013-06-25 - HTML5 & JavaScript Security
PDF
Easy tests with Selenide and Easyb
PDF
Testing in JavaScript - August 2018 - WebElement Bardejov
PDF
Polyglot automation - QA Fest - 2015
PDF
Unit Testing JavaScript Applications
PDF
Web-First Design Patterns
PDF
Kiss PageObjects [01-2017]
JavaScript Operators
2013-06-25 - HTML5 & JavaScript Security
Easy tests with Selenide and Easyb
Testing in JavaScript - August 2018 - WebElement Bardejov
Polyglot automation - QA Fest - 2015
Unit Testing JavaScript Applications
Web-First Design Patterns
Kiss PageObjects [01-2017]

What's hot (20)

PDF
Web ui tests examples with selenide, nselene, selene & capybara
PDF
Сергей Больщиков "Protractor Tips & Tricks"
PDF
Ajax
PDF
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
PDF
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
PPT
Activity lesson
ODP
Introduction to Angular js
PDF
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
PDF
Unit Test and TDD
PPT
Migration testing framework
PDF
Spock's New Tricks
DOC
Cis407 a ilab 5 web application development devry university
PDF
Modular Angular JS
PDF
Testing javascript in the frontend
PDF
The Ring programming language version 1.3 book - Part 30 of 88
PDF
TDD, BDD and mocks
PDF
Graphql, REST and Apollo
PDF
Testing Java Code Effectively - BaselOne17
PDF
The Road to Native Web Components
Web ui tests examples with selenide, nselene, selene & capybara
Сергей Больщиков "Protractor Tips & Tricks"
Ajax
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Activity lesson
Introduction to Angular js
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
Unit Test and TDD
Migration testing framework
Spock's New Tricks
Cis407 a ilab 5 web application development devry university
Modular Angular JS
Testing javascript in the frontend
The Ring programming language version 1.3 book - Part 30 of 88
TDD, BDD and mocks
Graphql, REST and Apollo
Testing Java Code Effectively - BaselOne17
The Road to Native Web Components
Ad

Viewers also liked (18)

PPTX
Клиента нужно знать в лицо. Crm битрикс24 для управления продажами
PDF
PPTX
PPTX
хортиця
PPTX
Ծաղկի բեղմնավորման մասին
PPTX
Оганнес Айвазовский
PPTX
О себе
PDF
Решения онлайн оплаты РФИ банка
DOCX
Ergonomija
PPT
Si em feu dir la cosa
PDF
RHB Creative #PortraitParty Guest List
PPT
Who do i call v2 2014
PDF
სოციალური მედია და ეროვნული უსაფრთხოება
PPTX
ePortfolio Implementation: It Takes A Village
PPT
атомная энергетика
PPTX
Зимний словарик
PPTX
C V OF SOCIAL ACTIVITY
Клиента нужно знать в лицо. Crm битрикс24 для управления продажами
хортиця
Ծաղկի բեղմնավորման մասին
Оганнес Айвазовский
О себе
Решения онлайн оплаты РФИ банка
Ergonomija
Si em feu dir la cosa
RHB Creative #PortraitParty Guest List
Who do i call v2 2014
სოციალური მედია და ეროვნული უსაფრთხოება
ePortfolio Implementation: It Takes A Village
атомная энергетика
Зимний словарик
C V OF SOCIAL ACTIVITY
Ad

Similar to Automated testing for client-side - Adam Klein, 500 Tech (20)

PDF
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
PDF
Javascript tdd byandreapaciolla
PDF
AngularJS Unit Testing w/Karma and Jasmine
PDF
Intro to Unit Testing in AngularJS
PPT
Testing in AngularJS
PDF
Describe's Full of It's
PPTX
Slaven tomac unit testing in angular js
PDF
Angularjs - Unit testing introduction
PDF
Angular Application Testing
PDF
An Introduction To Testing In AngularJS Applications
PPTX
AngularJS Unit Testing
PDF
Angular testing
PDF
Angularjs Test Driven Development (TDD)
ODP
Unit Testing and Coverage for AngularJS
PDF
Angular Intermediate
PDF
Test-Driven Development of AngularJS Applications
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
PPTX
Dive into Angular, part 5: Experience
PDF
Unit-testing and E2E testing in JS
PDF
AngularJS Testing
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
Javascript tdd byandreapaciolla
AngularJS Unit Testing w/Karma and Jasmine
Intro to Unit Testing in AngularJS
Testing in AngularJS
Describe's Full of It's
Slaven tomac unit testing in angular js
Angularjs - Unit testing introduction
Angular Application Testing
An Introduction To Testing In AngularJS Applications
AngularJS Unit Testing
Angular testing
Angularjs Test Driven Development (TDD)
Unit Testing and Coverage for AngularJS
Angular Intermediate
Test-Driven Development of AngularJS Applications
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Dive into Angular, part 5: Experience
Unit-testing and E2E testing in JS
AngularJS Testing

More from Codemotion Tel Aviv (20)

PDF
Keynote: Trends in Modern Application Development - Gilly Dekel, IBM
PDF
Angular is one fire(base)! - Shmuela Jacobs
PDF
Demystifying docker networking black magic - Lorenzo Fontana, Kiratech
PDF
Faster deep learning solutions from training to inference - Amitai Armon & Ni...
PDF
Facts about multithreading that'll keep you up at night - Guy Bar on, Vonage
PDF
Master the Art of the AST (and Take Control of Your JS!) - Yonatan Mevorach, ...
PDF
Unleash the power of angular Reactive Forms - Nir Kaufman, 500Tech
PDF
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
PDF
Actors and Microservices - Can two walk together? - Rotem Hermon, Gigya
PDF
How to Leverage Machine Learning (R, Hadoop, Spark, H2O) for Real Time Proces...
PDF
My Minecraft Smart Home: Prototyping the internet of uncanny things - Sascha ...
PDF
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
PDF
Containerised ASP.NET Core apps with Kubernetes
PDF
Fullstack DDD with ASP.NET Core and Anguar 2 - Ronald Harmsen, NForza
PDF
The Art of Decomposing Monoliths - Kfir Bloch, Wix
PDF
SOA Lessons Learnt (or Microservices done Better) - Sean Farmar, Particular S...
PDF
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
PDF
Getting Physical with Web Bluetooth - Uri Shaked, BlackBerry
PDF
Web based virtual reality - Tanay Pant, Mozilla
PDF
Material Design Demytified - Ran Nachmany, Google
Keynote: Trends in Modern Application Development - Gilly Dekel, IBM
Angular is one fire(base)! - Shmuela Jacobs
Demystifying docker networking black magic - Lorenzo Fontana, Kiratech
Faster deep learning solutions from training to inference - Amitai Armon & Ni...
Facts about multithreading that'll keep you up at night - Guy Bar on, Vonage
Master the Art of the AST (and Take Control of Your JS!) - Yonatan Mevorach, ...
Unleash the power of angular Reactive Forms - Nir Kaufman, 500Tech
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Actors and Microservices - Can two walk together? - Rotem Hermon, Gigya
How to Leverage Machine Learning (R, Hadoop, Spark, H2O) for Real Time Proces...
My Minecraft Smart Home: Prototyping the internet of uncanny things - Sascha ...
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
Containerised ASP.NET Core apps with Kubernetes
Fullstack DDD with ASP.NET Core and Anguar 2 - Ronald Harmsen, NForza
The Art of Decomposing Monoliths - Kfir Bloch, Wix
SOA Lessons Learnt (or Microservices done Better) - Sean Farmar, Particular S...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
Getting Physical with Web Bluetooth - Uri Shaked, BlackBerry
Web based virtual reality - Tanay Pant, Mozilla
Material Design Demytified - Ran Nachmany, Google

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
Teaching material agriculture food technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
NewMind AI Monthly Chronicles - July 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
CIFDAQ's Market Insight: SEC Turns Pro Crypto
NewMind AI Monthly Chronicles - July 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
20250228 LYD VKU AI Blended-Learning.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
Advanced methodologies resolving dimensionality complications for autism neur...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.

Automated testing for client-side - Adam Klein, 500 Tech

  • 2. Before we startBefore we start Hebrew or English? Don't wait for the "Questions?" slide I'm skipping the "why test?" intro
  • 4. Adam Klein CTO of 500Tech meetup.com/AngularJS-IL angular.co.il hackademy.co.il Among our clients: - Wix - Cellebrite - eToro - Autodesk - ... MeMe
  • 6. var Person = function(first, last) { this.fullname = function() { return first + ' ' + last; } } describe ('Person', function() { it('should return fullname correctly', function() { var p = new Person('Adam', 'Klein'); expect(p.fullname()).toEqual('Adam Klein'); }); }); ExampleExample
  • 7. It runs in the browserIt runs in the browser +1 on credibility+1 on credibility Let's see it in action
  • 8. Debugging the testDebugging the test chrome dev toolschrome dev tools
  • 9. JasmineJasmine What it is not: It's not a framework for running tests But karma is....
  • 10. Is a test running framework Makes the browser interaction seamless Works with various testing frameworks, not just jasmine KarmaKarma formerly testacular renamed because it resembles.... Let's see it live
  • 11. Run in severalRun in several browsers at oncebrowsers at once karma-firefox-launcher karma-chrome-launcher karma-phantomjs-launcher
  • 12. Other cool stuffOther cool stuff OSX reporter Coverage ...
  • 13. You might ask yourself, how the hell do IYou might ask yourself, how the hell do I unit test this code:unit test this code: <button onclick="addOne()"> Add one </button> <h1>0</h1> function addOne() { var count = $('h1'); var number = parseInt(count.text()); count.text(number + 1); } html Javascript
  • 14. Karma html2JS toKarma html2JS to the rescuethe rescue Load an html file in the current DOM Test the javascript that interacts with it
  • 15. Preparation document.body.innerHTML = __html__['views/index.html']; var button = $('button'); var h1 = $('h1'); it('should start with 0', function() { expect(h1.text()).toEqual('0'); }); it('should add one', function() { button.click(); expect(h1.text()).toEqual('1'); }); Test
  • 16. AngularJSAngularJS <div ng-controller="myController"> <button ng-click="addOne()"> Add one </button> <h1>{{count}}</h1> </div> function MyController($scope) { $scope.count = 0; $scope.addOne = function() { $scope.count++; } }
  • 17. AngularJSAngularJS Controller Handles view state Makes data and functions accessible via $scope Doesn't know DOM View (template) Data binding Glue events
  • 18. How the test will look likeHow the test will look like it('should bind h1 to count', function() { $scope.count = 10; $scope.$apply(); expect(h1.text()).toEqual('10'); }); it('should call add one on button click', function() { button.click(); expect($scope.addOne).toHaveBeenCalled(); });
  • 19. What about system testsWhat about system tests with Selenium you ask?with Selenium you ask? Good question!! Follow our twitter for my coming presentation on how to make maintainable, readable, and fast system tests.....
  • 20. Our mediaOur media Our presentations Cool libraries & services Interesting blog posts Courses & workshops @500TechIL 500Tech on facebook
  • 21. external serverexternal server productsService = { products: [], create: function(product) { var response = $.ajax(...); if(response.success) { this.products.push(product); } } }
  • 22. Easy to mockEasy to mock serverApi productsService actual server HTTP
  • 23. Something like thisSomething like this productsService = { products: [], create: function(product) { var response = serverApi.createProduct(product); if(response.success) { this.products.push(product); } } } serverApi = { createProduct: function(product) { $.ajax(...); } }
  • 24. Spy / Mock / Stub / FakeSpy / Mock / Stub / Fake spyOnspyOn var product = {name: 'product'}; spyOn(serverApi, 'createProduct').andReturn({success: true}); productsService.create(product); expect(productsService.products).toEqual([product]);
  • 25. Test the side effectTest the side effect expect(serverApi.createProduct). toHaveBeenCalledWith(product);
  • 26. Credibility alert!Credibility alert! Test might pass but code will fail The spies are the contract with the server
  • 27. Keep in TouchKeep in Touch @500TechIL blog.500tech.com meetup.com/angularjs-il meetup.com/hackademy hackademy.co.il