SlideShare a Scribd company logo
UI Testing
An unexpected Journey
Oren Farhi
JS Engineer (2006)
JS Group Leader @Tikal
Speaker (Israel & World Wide)
github.com/orizens
orizens.com
JSes6
B
Outline
1. What is UI testing
2. Why Should I Test UI
3. Hands On & Best Practices Patterns
a. Unit Testing
b. End To End Tests (E2E)
Demo App: Echoes Player
http://echotu.be (available as a chrome app)
github.com/orizens/echoes/tree/angular
What is UI Testing
perspective
UI Testing - Who Should Give a $#%&?
developer product end user qa / testers
Why Should I Test UI?
Why ?
In The Past...
1. Getting Requirements
2. Started writing code
3. now the cycle begins:
Save Code
Go To Browser & Refresh
Open Debugger
Automating The Debug Process
1. Add some “watches”
2. Add some “truthy” watches
3. Refresh
4. Try some other input
5. Repeat the “clicks”, “enter”, “keys” in
input
6. Refresh...
debugging, checking and repeating this process each time makes me go: ‘ahhhh’
I Should Write Test For UI
Because:
4 reasons
We’ve been doing that from the
beginning (maybe not with code)
Absence of Human Testers For Every Step
Automate the Dev & Tests Process
“Can You Make Sure Everything works?”
A UI Test = expecting something to be
What do we check anyway?
1. I expect something to be with a value
2. I expect something to be visible on the
DOM
3. I expect that click will change the search
4. I expect that a right click will show a
context menu, with user permissions
visible
5. I expect “<grid model=”items”>” to
render a data table in the DOM
Tools For Testing JS
Jasmine, Karma, phantom
What Is Jasmine.js
bdd js testing framework for testing js
Jasmine.js
by Pivotal
it’s a Standalone
BDD framework
for testing JS code
available on
github
1. Suites - describe()
2. Specs - it()
3. Expectations - expect()
4. Matchers - .not/.toBe()
● Spies
● Stubs
● Async
● skip tests - xit, xdescribe
Jasmine Syntax - BDD Style
describe('Gandalf the Gray', function () {
it("should stop balrog passing the bridge", function() {});
it("should save the hobbits when in danger", function() {});
})
What Is Karma Test Runner
automate: running tests, ci (jenkins, teamcity..),
multiple browsers, by angularjs team
Phantom.js - Headless Webkit
scriptable browser: includes js, DOM, routing etc..
Showtime 1 - Dropdown
testing dropdown directive in angular
Testing a Bootstrap Dropdown
<e-dropdown label="Preset"
items="presets"
on-select="onPresetChange(item)"
icon="tag"
></e-dropdown>
HTML - container rendered
it('should render a dropdown element', function () {
expect(element.hasClass('dropdown')).toBeTruthy();
});
<e-dropdown label="Preset"
items="presets"
on-select="onPresetChange(item)"
icon="tag"
></e-dropdown>
HTML - items rendered
it("should render items if given presets", function() {
expect(
element.find('ul li').length)
.toBe(
scope.presets.length
);
});
<e-dropdown label="Preset"
items="presets"
on-select="onPresetChange(item)"
icon="tag"
></e-dropdown>
HTML - Content is rendered
it("should render the label according to the 'label' attribute",
function() {
expect(
element.find('.dropdown-toggle').text().trim())
.toBe('Preset')
});
<e-dropdown label="Preset"
items="presets"
on-select="onPresetChange(item)"
icon="tag"
></e-dropdown>
Functionality - function called on clicked
it("should call a function when select has changed",function() {
spyOn(scope, 'onPresetChange');
element.isolateScope().handleClick(scope.presets[0]);
expect(scope.onPresetChange).toHaveBeenCalled();
});
<e-dropdown label="Preset"
items="presets"
on-select="onPresetChange(item)"
icon="tag"
></e-dropdown>
Functionality using Spy - click
it("should call a function with the selected item when select
has changed", function() {
spyOn(scope, 'onPresetChange');
element.isolateScope().handleClick(scope.presets[0]);
expect(scope.onPresetChange).toHaveBeenCalledWith(scope.presets
[0]);
});
<e-dropdown label="Preset"
items="presets"
on-select="onPresetChange(item)"
icon="tag"
></e-dropdown>
Showtime #2 - Testing Ajax
mocks and stubs using angularjs services
Preparing Mocks
var mockData = window.mocks[‘video.items.mock’];
var url = /.+search.*/
karma-json-fixtures-preprocessor
add to json paths to configuration of:
files: [ '../tests/mocks/**/*mock.json' ]
preprocessor: {
'../tests/mocks/**/*mock.json': ['json_fixtures']
}
Functionality using Spy and Fake
it("set the feed type when changed in YoutubeSearch and perform
search", function(){
httpBackend.whenGET(url).respond(mockData);
spyOn(scope, 'searchYoutube').and.returnValue('done')
spyOn(YoutubeSearchSrv, 'setType').and.callFake(function(){
return 'set';
});
rootScope.$broadcast('feed-type-changed', 'playlist');
scope.$digest();
expect(YoutubeSearchSrv.setType).toHaveBeenCalled();
expect(YoutubeSearchSrv.setType.calls.count()).toEqual(1);
expect(scope.searchYoutube).toHaveBeenCalled();
expect(scope.searchYoutube.calls.count()).toEqual(1);
})
Testing Ajax
stubs & mocks
Mocking Ajax Call
describe("Media Info :", function() {...})
it("should update the video's title when video has changed",
function() {
var video = mockMediaInfoItems.items[0];
httpBackend.whenGET(/.+videos.*/).respond(mockMediaInfo);
YoutubePlayerSettings.playVideoId(video);
scope.$apply();
expect(scope.vm.video.title).toEqual(video.snippet.title);
});
End to End Testing (E2E)
towards the rest of the world
What is E2E
tests few pieces together
regarding ui:
web ui = > rest of the world
E2E for JS
for angular.js
JS syntax
all browsers
for any js app
Gherkin syntax
all browsers
E2E with Pioneer.js
Feature: Simple Feature
Background:
Given I visit Echoes Player
Scenario: Entering Information
When I search for "alice in chains live"
Then I should see 50 results
PioneerJS “When” Example
this.When(/^I search for "([^"]*)"$/, function(value){
var MediaSearch = this.Widget.extend({
root: "#media-search",
setSearchQuery: function (val) {
return this.fill(val);
}
})
var search = new MediaSearch();
return this.driver.sleep(10000).then(function(){
search.sendKeys('', Driver.Key.ENTER).then(function(){
search.setSearchQuery(value);
return search.sendKeys(Driver.Key.ENTER);
});
});
});
So - What are the benefits?
Show me the money
What is Good with UI Unit Testing
● Adding Features won’t break code’s
behaviour
● promotes writing modular logics
● Forces writing high quality code -
decoupling
● documentation - code intention &
functional behavior
The End
Q & A

More Related Content

What's hot (20)

PDF
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Codemotion
 
PDF
Front-End Testing: Demystified
Seth McLaughlin
 
PDF
Night Watch with QA
Carsten Sandtner
 
PDF
Testing Web Applications
Seth McLaughlin
 
PDF
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Oren Rubin
 
PPTX
Automated UI Testing Done Right (QMSDNUG)
Mehdi Khalili
 
ZIP
Automated Frontend Testing
Neil Crosby
 
PPTX
Angular UI Testing with Protractor
Andrew Eisenberg
 
PPTX
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
PDF
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
PDF
Introduction To Web Application Testing
Ynon Perek
 
PDF
High Performance JavaScript 2011
Nicholas Zakas
 
PPTX
Testing Ext JS and Sencha Touch
Mats Bryntse
 
PPTX
Breaking free from static abuse in test automation frameworks and using Sprin...
Abhijeet Vaikar
 
PDF
UI Testing Automation
AgileEngine
 
PPTX
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
Jim Lane
 
DOC
Selenium Automation Using Ruby
Kumari Warsha Goel
 
PDF
Front-end Automated Testing
Ruben Teijeiro
 
PDF
Building testable chrome extensions
Seth McLaughlin
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Codemotion
 
Front-End Testing: Demystified
Seth McLaughlin
 
Night Watch with QA
Carsten Sandtner
 
Testing Web Applications
Seth McLaughlin
 
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Oren Rubin
 
Automated UI Testing Done Right (QMSDNUG)
Mehdi Khalili
 
Automated Frontend Testing
Neil Crosby
 
Angular UI Testing with Protractor
Andrew Eisenberg
 
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
Introduction To Web Application Testing
Ynon Perek
 
High Performance JavaScript 2011
Nicholas Zakas
 
Testing Ext JS and Sencha Touch
Mats Bryntse
 
Breaking free from static abuse in test automation frameworks and using Sprin...
Abhijeet Vaikar
 
UI Testing Automation
AgileEngine
 
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
Jim Lane
 
Selenium Automation Using Ruby
Kumari Warsha Goel
 
Front-end Automated Testing
Ruben Teijeiro
 
Building testable chrome extensions
Seth McLaughlin
 

Viewers also liked (20)

PPTX
User Interface Testing | Best Practices
David Tzemach
 
PPTX
Testing the User Interface - Coded UI Tests with Visual Studio 2010
Eric D. Boyd
 
PPTX
Agile scrum roles
David Tzemach
 
PDF
GSF - The UI / UX Design philosphy
Zariyaa Consulting
 
PDF
Introducción a la programación y la informática. Tema 5
Andres Garcia Garcia
 
PDF
Introducción a la programación y la informática. Tema 8
Andres Garcia Garcia
 
PDF
Introducción a la programación y la informática. Tema 6
Andres Garcia Garcia
 
PDF
Introducción a la programación y la informática. Tema 4
Andres Garcia Garcia
 
PDF
Introducción a la programación y la informática. Tema 9
Andres Garcia Garcia
 
PDF
Introducción a la programación y la informática. Tema 7
Andres Garcia Garcia
 
PDF
Introducción a la programación y la informática. Tema 2
Andres Garcia Garcia
 
PPT
Combining Methods: Web Analytics and User Testing
User Intelligence
 
PDF
Testing responsive web design pdf
crilusi
 
PDF
UX Design Testing Battle School - ISL
Eric Shutt
 
PDF
UI Testing with Earl Grey
Shyam Bhat
 
PDF
Introducción a la programación y la informática. Tema 3
Andres Garcia Garcia
 
KEY
Ui BDD Testing
Taras Kalapun
 
PPTX
The evolution of agile development process
David Tzemach
 
PPTX
Visual Regression Testing
VodqaBLR
 
PPTX
All you need to know about regression testing | David Tzemach
David Tzemach
 
User Interface Testing | Best Practices
David Tzemach
 
Testing the User Interface - Coded UI Tests with Visual Studio 2010
Eric D. Boyd
 
Agile scrum roles
David Tzemach
 
GSF - The UI / UX Design philosphy
Zariyaa Consulting
 
Introducción a la programación y la informática. Tema 5
Andres Garcia Garcia
 
Introducción a la programación y la informática. Tema 8
Andres Garcia Garcia
 
Introducción a la programación y la informática. Tema 6
Andres Garcia Garcia
 
Introducción a la programación y la informática. Tema 4
Andres Garcia Garcia
 
Introducción a la programación y la informática. Tema 9
Andres Garcia Garcia
 
Introducción a la programación y la informática. Tema 7
Andres Garcia Garcia
 
Introducción a la programación y la informática. Tema 2
Andres Garcia Garcia
 
Combining Methods: Web Analytics and User Testing
User Intelligence
 
Testing responsive web design pdf
crilusi
 
UX Design Testing Battle School - ISL
Eric Shutt
 
UI Testing with Earl Grey
Shyam Bhat
 
Introducción a la programación y la informática. Tema 3
Andres Garcia Garcia
 
Ui BDD Testing
Taras Kalapun
 
The evolution of agile development process
David Tzemach
 
Visual Regression Testing
VodqaBLR
 
All you need to know about regression testing | David Tzemach
David Tzemach
 
Ad

Similar to UI Testing Best Practices - An Expected Journey (20)

PDF
Angularjs - Unit testing introduction
Nir Kaufman
 
PDF
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
PPTX
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
PPTX
Test driven development with Jasmine
harshit040591
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
PDF
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
PDF
Front end unit testing using jasmine
Gil Fink
 
PPTX
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
ODP
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
PPT
Testing in AngularJS
Peter Drinnan
 
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
PPTX
Java script unit testing
Mats Bryntse
 
PPTX
Testing JavaScript with Jasmine in Rails Applications
Hector Correa
 
PDF
Reliable Javascript
Glenn Stovall
 
PDF
An Introduction To Testing In AngularJS Applications
Rohan Chandane
 
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
PPT
Jasmine presentation Selenium Camp 2013
dimakovalenko
 
PDF
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PPTX
Angular Unit Testing
Avi Engelshtein
 
Angularjs - Unit testing introduction
Nir Kaufman
 
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Test driven development with Jasmine
harshit040591
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
Front end unit testing using jasmine
Gil Fink
 
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
Testing in AngularJS
Peter Drinnan
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
Java script unit testing
Mats Bryntse
 
Testing JavaScript with Jasmine in Rails Applications
Hector Correa
 
Reliable Javascript
Glenn Stovall
 
An Introduction To Testing In AngularJS Applications
Rohan Chandane
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
Jasmine presentation Selenium Camp 2013
dimakovalenko
 
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Angular Unit Testing
Avi Engelshtein
 
Ad

Recently uploaded (20)

PPTX
Orchestrating things in Angular application
Peter Abraham
 
PDF
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PDF
The Internet - By the numbers, presented at npNOG 11
APNIC
 
PPTX
Networking_Essentials_version_3.0_-_Module_5.pptx
ryan622010
 
PDF
BRKAPP-1102 - Proactive Network and Application Monitoring.pdf
fcesargonca
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
PPTX
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PDF
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
PDF
FutureCon Seattle 2025 Presentation Slides - You Had One Job
Suzanne Aldrich
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PDF
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
ssuser73bdb11
 
PDF
Digital burnout toolkit for youth workers and teachers
asociatiastart123
 
PPTX
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
PDF
Top 10 Testing Procedures to Ensure Your Magento to Shopify Migration Success...
CartCoders
 
PDF
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
PPTX
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
PPTX
Networking_Essentials_version_3.0_-_Module_3.pptx
ryan622010
 
Orchestrating things in Angular application
Peter Abraham
 
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
The Internet - By the numbers, presented at npNOG 11
APNIC
 
Networking_Essentials_version_3.0_-_Module_5.pptx
ryan622010
 
BRKAPP-1102 - Proactive Network and Application Monitoring.pdf
fcesargonca
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
FutureCon Seattle 2025 Presentation Slides - You Had One Job
Suzanne Aldrich
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
ssuser73bdb11
 
Digital burnout toolkit for youth workers and teachers
asociatiastart123
 
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
Top 10 Testing Procedures to Ensure Your Magento to Shopify Migration Success...
CartCoders
 
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
Networking_Essentials_version_3.0_-_Module_3.pptx
ryan622010
 

UI Testing Best Practices - An Expected Journey

  • 2. Oren Farhi JS Engineer (2006) JS Group Leader @Tikal Speaker (Israel & World Wide) github.com/orizens orizens.com JSes6 B
  • 3. Outline 1. What is UI testing 2. Why Should I Test UI 3. Hands On & Best Practices Patterns a. Unit Testing b. End To End Tests (E2E)
  • 4. Demo App: Echoes Player http://echotu.be (available as a chrome app) github.com/orizens/echoes/tree/angular
  • 5. What is UI Testing perspective
  • 6. UI Testing - Who Should Give a $#%&? developer product end user qa / testers
  • 7. Why Should I Test UI? Why ?
  • 8. In The Past... 1. Getting Requirements 2. Started writing code 3. now the cycle begins:
  • 10. Go To Browser & Refresh
  • 12. Automating The Debug Process 1. Add some “watches” 2. Add some “truthy” watches 3. Refresh 4. Try some other input 5. Repeat the “clicks”, “enter”, “keys” in input 6. Refresh...
  • 13. debugging, checking and repeating this process each time makes me go: ‘ahhhh’
  • 14. I Should Write Test For UI Because: 4 reasons
  • 15. We’ve been doing that from the beginning (maybe not with code)
  • 16. Absence of Human Testers For Every Step
  • 17. Automate the Dev & Tests Process
  • 18. “Can You Make Sure Everything works?”
  • 19. A UI Test = expecting something to be What do we check anyway? 1. I expect something to be with a value 2. I expect something to be visible on the DOM 3. I expect that click will change the search 4. I expect that a right click will show a context menu, with user permissions visible 5. I expect “<grid model=”items”>” to render a data table in the DOM
  • 20. Tools For Testing JS Jasmine, Karma, phantom
  • 21. What Is Jasmine.js bdd js testing framework for testing js
  • 22. Jasmine.js by Pivotal it’s a Standalone BDD framework for testing JS code available on github 1. Suites - describe() 2. Specs - it() 3. Expectations - expect() 4. Matchers - .not/.toBe() ● Spies ● Stubs ● Async ● skip tests - xit, xdescribe
  • 23. Jasmine Syntax - BDD Style describe('Gandalf the Gray', function () { it("should stop balrog passing the bridge", function() {}); it("should save the hobbits when in danger", function() {}); })
  • 24. What Is Karma Test Runner automate: running tests, ci (jenkins, teamcity..), multiple browsers, by angularjs team
  • 25. Phantom.js - Headless Webkit scriptable browser: includes js, DOM, routing etc..
  • 26. Showtime 1 - Dropdown testing dropdown directive in angular
  • 27. Testing a Bootstrap Dropdown <e-dropdown label="Preset" items="presets" on-select="onPresetChange(item)" icon="tag" ></e-dropdown>
  • 28. HTML - container rendered it('should render a dropdown element', function () { expect(element.hasClass('dropdown')).toBeTruthy(); }); <e-dropdown label="Preset" items="presets" on-select="onPresetChange(item)" icon="tag" ></e-dropdown>
  • 29. HTML - items rendered it("should render items if given presets", function() { expect( element.find('ul li').length) .toBe( scope.presets.length ); }); <e-dropdown label="Preset" items="presets" on-select="onPresetChange(item)" icon="tag" ></e-dropdown>
  • 30. HTML - Content is rendered it("should render the label according to the 'label' attribute", function() { expect( element.find('.dropdown-toggle').text().trim()) .toBe('Preset') }); <e-dropdown label="Preset" items="presets" on-select="onPresetChange(item)" icon="tag" ></e-dropdown>
  • 31. Functionality - function called on clicked it("should call a function when select has changed",function() { spyOn(scope, 'onPresetChange'); element.isolateScope().handleClick(scope.presets[0]); expect(scope.onPresetChange).toHaveBeenCalled(); }); <e-dropdown label="Preset" items="presets" on-select="onPresetChange(item)" icon="tag" ></e-dropdown>
  • 32. Functionality using Spy - click it("should call a function with the selected item when select has changed", function() { spyOn(scope, 'onPresetChange'); element.isolateScope().handleClick(scope.presets[0]); expect(scope.onPresetChange).toHaveBeenCalledWith(scope.presets [0]); }); <e-dropdown label="Preset" items="presets" on-select="onPresetChange(item)" icon="tag" ></e-dropdown>
  • 33. Showtime #2 - Testing Ajax mocks and stubs using angularjs services
  • 34. Preparing Mocks var mockData = window.mocks[‘video.items.mock’]; var url = /.+search.*/ karma-json-fixtures-preprocessor add to json paths to configuration of: files: [ '../tests/mocks/**/*mock.json' ] preprocessor: { '../tests/mocks/**/*mock.json': ['json_fixtures'] }
  • 35. Functionality using Spy and Fake it("set the feed type when changed in YoutubeSearch and perform search", function(){ httpBackend.whenGET(url).respond(mockData); spyOn(scope, 'searchYoutube').and.returnValue('done') spyOn(YoutubeSearchSrv, 'setType').and.callFake(function(){ return 'set'; }); rootScope.$broadcast('feed-type-changed', 'playlist'); scope.$digest(); expect(YoutubeSearchSrv.setType).toHaveBeenCalled(); expect(YoutubeSearchSrv.setType.calls.count()).toEqual(1); expect(scope.searchYoutube).toHaveBeenCalled(); expect(scope.searchYoutube.calls.count()).toEqual(1); })
  • 37. Mocking Ajax Call describe("Media Info :", function() {...}) it("should update the video's title when video has changed", function() { var video = mockMediaInfoItems.items[0]; httpBackend.whenGET(/.+videos.*/).respond(mockMediaInfo); YoutubePlayerSettings.playVideoId(video); scope.$apply(); expect(scope.vm.video.title).toEqual(video.snippet.title); });
  • 38. End to End Testing (E2E) towards the rest of the world
  • 39. What is E2E tests few pieces together regarding ui: web ui = > rest of the world
  • 40. E2E for JS for angular.js JS syntax all browsers for any js app Gherkin syntax all browsers
  • 41. E2E with Pioneer.js Feature: Simple Feature Background: Given I visit Echoes Player Scenario: Entering Information When I search for "alice in chains live" Then I should see 50 results
  • 42. PioneerJS “When” Example this.When(/^I search for "([^"]*)"$/, function(value){ var MediaSearch = this.Widget.extend({ root: "#media-search", setSearchQuery: function (val) { return this.fill(val); } }) var search = new MediaSearch(); return this.driver.sleep(10000).then(function(){ search.sendKeys('', Driver.Key.ENTER).then(function(){ search.setSearchQuery(value); return search.sendKeys(Driver.Key.ENTER); }); }); });
  • 43. So - What are the benefits? Show me the money
  • 44. What is Good with UI Unit Testing ● Adding Features won’t break code’s behaviour ● promotes writing modular logics ● Forces writing high quality code - decoupling ● documentation - code intention & functional behavior