SlideShare a Scribd company logo
Writing better tests for your
JavaScript app
Jake Ginnivan
‘Better’ Tests?
Fast
Comprehensive
Reliable
Maintainable
Increased confidence
Enables refactoring
Typical Problems when testing…
• Slow to write
• Slow to run
• Intermittently fail
• Do not fail
• Prevent refactoring
• Don’t catch issues
Why write tests?
Why write tests?
Deploy with confidence
Writing better tests for your java script app
Writing better tests for your
JavaScript app
Jake Ginnivan
TestStack
White
Seleno
ConventionTests
BDDfy
Shouldly
Digital Development Manager @
Writing better tests for your java script app
Some testing scenarios
You don’t have much testing, and want to get as much confidence with
as little work as possible
You have found a bug which is really easy to fix, how do you ensure it
doesn’t happen again
You have a feature which is critical and has a large impact if there are
issues
There is no single testing
strategy!
Unit tests
In process
Isolated
Fast
Test one thing
Module
Function
Fast
Comprehensive
Reliable
Maintainable
Increased confidence
Not restrictive
Unit tests
Pros
• Fast to write
• Fast to run
• Easy to debug
Cons
• Can inhibit refactoring
• Delete them and re-write
• Does not find collaboration
issues between modules
• Need higher level tests to
accompany them
Unit tests – Test runner
Unit testing
DEMO
Unit tests
• Keep modules pure
• Mocks are potential design issues
Higher level unit tests
Also known as acceptance tests, behaviour tests, collaboration tests, boundary
tests and many other things
Unit Tests
In process
Isolated
Fast
Test one thing
Fast
Speed of
development
Reliable
Maintainable
Increased confidence
Not restrictive
Higher level Unit Tests
In process
Isolated
Fast
Test one thing
Fast
Speed of
development
Reliable
Maintainable
Increased confidence
Not restrictive
Higher Level Unit tests
Pros
• Fast to write
• Pretty Fast to run
• Covers module interactions
• Less prone to breaking during
refactoring
Cons
• Harder to debug than unit tests
• Cannot cover all scenarios
• Combinatorial issue
Higher level unit tests – tips / techniques
• An approach to testing single page apps
• Testing an express API
Client SPA Context
• Mock / Polyfill the DOM (JSDom)
• Mock external services (Sockets, HTTP Calls)
• Create a DOM instance and mount your application into it
• State based testing
• Raise events, interact with application, ensure it does what you want
Node web service context
• Create an mockable abstraction for any external systems
• Database
• Other services
• Reduce logic in express middlewares
• If you are not going to start an in memory express server
• Use mediator pattern to introduce middlewares not tied to your http server
• Use subcutaneous style testing
Ports and adapters
Source: http://www.dossier-andreas.net/software_architecture/ports_and_adapters.html
Ports and adapters
export default {
emailSender: function(details) {
eventEmitter.publish(‘sendEmail’, details)
}
}
eventEmitter.on(‘sendEmail’, (details) => {
// actually send email
})
eventEmitter.on(‘sendEmail’, (details) => {
console.log(‘Pretending to send email’)
})
Integration tests
Integration Tests
Out of process communication
Slow
Often shared mutable state
Fast
Speed of
Development
Reliable
Maintainable
Increased confidence
Not restrictive
UI tests
UI Tests
Fragile
Slow
Fast
Speed of
Development
Reliable
Maintainable
Increased confidence
Not restrictive
Useful testing patterns
Defensive tests
The seam
function getCheckins(testDb) {
var db = testDb || connection
return db('checkin')
.select()
}
Arrange, Act, Assert
it('can search for whisky', async () => {
// Arrange
fetchMock.get('http://localhost:3001/whiskys?q=glen', [
{"id":99901,"name":"Glenmorangie Signet","region":""}
])
const app = mount(<App />)
// Act
const input = app.find('#searchBox')
input.simulate('change', { target: { value: 'glenm' }})
await wait(800)
// Assert
expect(app.find('span').text()).toBe('Glenmorangie Signet')
})
Page Object Pattern
class AppPage {
constructor() {
this.app = mount(<App />)
}
async searchForWhisky(term) {
const input = app.find('#searchBox')
input.simulate('change', { target: { value: term }})
}
getResults() {
return this.app.find('span').text()
}
}
Writing better tests for your java script app
Writing better tests for your java script app
Recap
• Test in Node
• Snapshot testing is awesome
• Different tests are a trade off, mix, blend and experiment to get what
you need
• Tests do not have to be painful
• Tests increase confidence so you can deploy and make your customers
happy!
Thanks!
Questions?

More Related Content

PDF
Agile Testing
PPTX
Manual, Visual, and Automated Testing For Web Apps
PPTX
Getting Started With Selenium
PPTX
Visual Studio 2010 Testing for Developers
PPTX
Test Design + Environment Management: Scaling UI Automation for Agile
PPTX
5 Considerations When Adopting Automated Testing
PPTX
Sustainable Automation Frameworks by Kelsey Shannahan
PDF
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Agile Testing
Manual, Visual, and Automated Testing For Web Apps
Getting Started With Selenium
Visual Studio 2010 Testing for Developers
Test Design + Environment Management: Scaling UI Automation for Agile
5 Considerations When Adopting Automated Testing
Sustainable Automation Frameworks by Kelsey Shannahan
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...

What's hot (20)

PPTX
ASP.NET & Unit Testing
PPTX
Brace yourself from automation death trap
PPTX
Test Automation Architecture That Works by Bhupesh Dahal
PDF
Automated Testing of Web Applications
DOCX
Automation Frame works Instruction Sheet
PPTX
Automated Test Framework with Cucumber
PPTX
Cypress test techniques cucumber bdd framework,tdd,api tests course
PPTX
QAorHighway2016
PPTX
TFS 2010: Team Development on Crack
PDF
Testing Web Services - QA or the Highway 2016
PPTX
Bdd with Cucumber and Mocha
PPTX
Thucydides – next generation acceptance testing with WebDriver
PPTX
Design patterns in test automation
PPTX
JavaScript Unit Testing
PPTX
QA Automation testing online training
PPTX
Selenium Design Patterns
PDF
Continuous Testing Meets the Classroom at Code.org
PPTX
ASP.NET 5 & Unit Testing
PDF
Cucumber ppt
PPTX
BDD with SpecFlow and Selenium
ASP.NET & Unit Testing
Brace yourself from automation death trap
Test Automation Architecture That Works by Bhupesh Dahal
Automated Testing of Web Applications
Automation Frame works Instruction Sheet
Automated Test Framework with Cucumber
Cypress test techniques cucumber bdd framework,tdd,api tests course
QAorHighway2016
TFS 2010: Team Development on Crack
Testing Web Services - QA or the Highway 2016
Bdd with Cucumber and Mocha
Thucydides – next generation acceptance testing with WebDriver
Design patterns in test automation
JavaScript Unit Testing
QA Automation testing online training
Selenium Design Patterns
Continuous Testing Meets the Classroom at Code.org
ASP.NET 5 & Unit Testing
Cucumber ppt
BDD with SpecFlow and Selenium
Ad

Viewers also liked (20)

PPTX
PDF
Las cooperativas
DOCX
Proyecto convergencia
PDF
C2 writing guide
DOCX
Extraordinario marco esteban soberanis cetz
PDF
Extraordinario marco esteban soberanis cetz
PDF
Papeleria
PPTX
O urso rabugento
PPTX
Lindo país - Luiz de carvalho
PPTX
El elemento
PPTX
Problem Based Learning in a Global World
PDF
Aula 2 revisado[2][1]
PPTX
The Spine and Its Vulnerability to Disc Rupture and Herniation
PDF
Simple Decision Tree Analysis
PPTX
Etude Volkswagen
PPTX
Application of molecular tools in environmental engineering (with references)
PPTX
Trastornos ligados al cromosoma x
PPT
Actividad sesion 3
PPT
Tema 8
PDF
Ciberbullying, Grooming y Sexting
Las cooperativas
Proyecto convergencia
C2 writing guide
Extraordinario marco esteban soberanis cetz
Extraordinario marco esteban soberanis cetz
Papeleria
O urso rabugento
Lindo país - Luiz de carvalho
El elemento
Problem Based Learning in a Global World
Aula 2 revisado[2][1]
The Spine and Its Vulnerability to Disc Rupture and Herniation
Simple Decision Tree Analysis
Etude Volkswagen
Application of molecular tools in environmental engineering (with references)
Trastornos ligados al cromosoma x
Actividad sesion 3
Tema 8
Ciberbullying, Grooming y Sexting
Ad

Similar to Writing better tests for your java script app (20)

PPTX
Test Driven Development - a Practitioner’s Perspective
PPTX
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
PPTX
Designing Self-maintaining UI Tests for Web Applications
PPTX
Test studiowebinaraugcodedstep
PPTX
Advanced Test Driven-Development @ php[tek] 2024
PPTX
Test Automation Pyramid
PDF
Agile testing
PPTX
Helpful Automation Techniques - Selenium Camp 2014
PPTX
Java script unit testing
PDF
Automated testing in javascript
PPTX
Testing of React JS app
PDF
What is this agile thing anyway
PDF
Test Driven Development
PPTX
Unit testing
PPTX
Test automation lesson
PDF
Tech Talk on Cloud Computing
PDF
Cloud-based Test Microservices JavaOne 2014
PPTX
Load testing with Visual Studio and Azure - Andrew Siemer
PPTX
Cross browser Testing JavaScript
PDF
Agile Engineering Best Practices by Richard Cheng
Test Driven Development - a Practitioner’s Perspective
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
Designing Self-maintaining UI Tests for Web Applications
Test studiowebinaraugcodedstep
Advanced Test Driven-Development @ php[tek] 2024
Test Automation Pyramid
Agile testing
Helpful Automation Techniques - Selenium Camp 2014
Java script unit testing
Automated testing in javascript
Testing of React JS app
What is this agile thing anyway
Test Driven Development
Unit testing
Test automation lesson
Tech Talk on Cloud Computing
Cloud-based Test Microservices JavaOne 2014
Load testing with Visual Studio and Azure - Andrew Siemer
Cross browser Testing JavaScript
Agile Engineering Best Practices by Richard Cheng

Recently uploaded (20)

PPT
JAVA ppt tutorial basics to learn java programming
PDF
top salesforce developer skills in 2025.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Online Work Permit System for Fast Permit Processing
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
System and Network Administraation Chapter 3
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Transform Your Business with a Software ERP System
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
ai tools demonstartion for schools and inter college
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
medical staffing services at VALiNTRY
PPTX
Essential Infomation Tech presentation.pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Digital Strategies for Manufacturing Companies
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPT
Introduction Database Management System for Course Database
JAVA ppt tutorial basics to learn java programming
top salesforce developer skills in 2025.pdf
How Creative Agencies Leverage Project Management Software.pdf
Odoo POS Development Services by CandidRoot Solutions
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Online Work Permit System for Fast Permit Processing
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
System and Network Administraation Chapter 3
How to Choose the Right IT Partner for Your Business in Malaysia
Transform Your Business with a Software ERP System
Understanding Forklifts - TECH EHS Solution
ai tools demonstartion for schools and inter college
Design an Analysis of Algorithms I-SECS-1021-03
Design an Analysis of Algorithms II-SECS-1021-03
medical staffing services at VALiNTRY
Essential Infomation Tech presentation.pptx
PTS Company Brochure 2025 (1).pdf.......
Digital Strategies for Manufacturing Companies
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction Database Management System for Course Database

Writing better tests for your java script app

Editor's Notes

  • #2: Good afternoon, how has everyones conference been? There has been so many great talks over the past few days, personally I really enjoyed ____ and ____ amongst others. Today we are going to be talking about how to write better tests for your JavaScript app, to do that we need to quality what I mean by ‘better’?
  • #3: Fast / Comprehensive --- Number of tests vs coverage? Reliable / Maintainable --- No race conditions, trusted, easy to maintain and keep up to date Valuable / Non-restrictive --- Do the tests find bugs? Can you refactor without breaking heaps of tests?
  • #5: We are payed to write software, not tests. The reason we write tests is to give us confidence to ship the software we write.
  • #6: We are payed to write software, not tests. The reason we write tests is to give us confidence to ship the software we write.
  • #8: To make your customers happy
  • #9: Good afternoon, how has everyones conference been? There has been so many great talks over the past few days, personally I really enjoyed ____ and ____ amongst others. Today we are going to be talking about how to write better tests for your JavaScript app, to do that we need to quality what I mean by ‘better’?
  • #10: Then…
  • #13: Lets explore this more
  • #16: Use node, way fast to bootstrap and unit tests are not trying to test browser compat
  • #17: searchLatest
  • #19: There is no common taxonomy on types of tests, the important thing to focus on is the characteristics of each type of test!
  • #24: I use React, Redux, but redux is transparent. This approach can be used with most UI libraries and is far far faster than using karma and real browsers, but you are testing in a different environment that your application will actually run in..
  • #40: We are payed to write software, not tests. The reason we write tests is to give us confidence to ship the software we write.