ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
An Existential Guide to
Testing React UIs
Who am I?
@bookstein
Artist: Alexandra Levasseur
Who am I?
@bookstein
Artist: Alexandra Levasseur
Where do I come from?
What is this all about?
¡ñ Unit tests
¡ñ Existentialism
Existential Testing Questions
¡ñ Should we write unit tests
for the UI?
¡ñ What matters to test?
¡ñ What should we not test?
Should we write unit tests for the UI?
My donation-tracking app
Very quick demo
The UI is not alone
Should we write unit tests for the UI?
YES
Let¡¯s get existential about tests
What matters to
test?
What matters to
not test?
Questions worth asking
There¡¯s no recipe
¡°Ten or twenty years from now we'll likely
have a more universal theory of which tests to
write, which tests not to write, and how to tell
the difference. In the meantime,
experimentation seems in order.¡±
- Kent Beck, test coverage guy
Artist: Andrew Baines
So why am I talking about this?
What matters to test?
The component to test
friend.js
1. Happy path
2. Behavior
3. Edge cases
1. Happy path
The DOM output you
expect
1. Happy path // Jest
1. Happy path // how do snapshots work?
capture markup
1. Happy path // how do snapshots work?
exports[`renders without crashing 1`] = `
<div className=¡±Friend¡±>
<div>
<h1>myFriendName</h1>
<p className=¡±Friend__Tags¡±>
Tags:
...
friend.test.js.snap
it('renders without crashing', () => {
const component = renderer.create(<Friend {...PROPS}
/>)
// ...
})
1. Happy path // snapshot test
friend.test.js
it('renders without crashing', () => {
const component = renderer.create(<Friend {...PROPS}
/>)
let tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
1. Happy path // snapshot test
friend.test.js
1. Happy path // snapshot test
2. Behavior
What should it do?
2. Behavior // Enzyme
Traverse/manipulateWrap component
2. Behavior // User input
friend.js
it('calls the `remove` callback on click', () => {
const wrapper = shallow(<Friend {...PROPS}/>)
// ...
})
2. Behavior // User input
friend.test.js
const removeFriend = jest.fn()
// ...pass in removeFriend with PROPS
it('calls the `remove` callback on click', () => {
const wrapper = shallow(<Friend {...PROPS}/>)
// ...
})
2. Behavior // User input
friend.test.js
const removeFriend = jest.fn()
it('calls the `remove` callback on click', () => {
const wrapper = shallow(<Friend {...PROPS}/>)
wrapper.find(`.Friend_X¡¯).simulate(¡®click¡¯)
expect(removeFriend).toHaveBeenCalled()
})
2. Behavior // User input
friend.test.js
3. Edge cases
Bad things happen
3. Edge cases // Jest mocks
MocksSnapshots
3. Edge cases // Mock network error
friendsList.js
export const pushToDatabase = (data) => {
return firebase
.database()
.ref(¡®friends¡¯)
.push()
.set(data)
}
3. Edge cases // Mock network error
firebaseService.js
jest.mock(¡®../firebaseService¡¯, () => {
return {
pushToDatabase: jest.fn(),
}
})
3. Edge cases // Mock network error
friendsList.test.js
it('sets error state if Firebase returns err¡¯, (done) => {
firebaseService.pushToDatabase
.mockImplementationOnce(() => // ...
})
3. Edge cases // Mock network error
friendsList.test.js
it('sets error state if Firebase returns err¡¯, (done) => {
firebaseService.pushToDatabase
.mockImplementationOnce(() => Promise.reject(¡®you got an
error!¡¯))
// ...
})
3. Edge cases // Mock network error
friendsList.test.js
1. Happy path 2. Behavior 3. Edge cases
1. Happy path 2. Behavior 3. Edge cases
Don¡¯t wait to write tests!
A brand new test
// HAPPY PATH:
// component renders as we expect
// BEHAVIOR:
// what behavior does the component itself have?
// EDGE CASES:
// what failure cases should our component handle?
friendsList.test.js
Yay! Our UI is tested!
Artist: Rafal Olbinski
What matters to not test?
Not in a unit test
¡ñ server logic
Artist: Rene Magritte
Not in a unit test
¡ñ server logic
¡ñ 3rd party components
Not in a unit test
¡ñ server logic
¡ñ 3rd party components
¡ñ anything you can¡¯t
control
Edges
An example edge
class FriendsList {
componentDidMount() {
firebase.database()...on('child_added',
snapshot => {// update state})
}
friendsList.js
An example edge
firebase.database()friendsList.js
Let¡¯s move the edge
class FriendsList {
componentDidMount() {
firebase.database()...on('child_added',
snapshot => {// update state})
}
friendsList.js
Let¡¯s move the edge
import { listenForUpdates } from ¡®../firebaseService¡¯
class FriendsList {
componentDidMount() {
listenForUpdates(snapshot => // update state)
}
friendsList.js
So cutting-edge
Firebase
Service.
js
So cutting-edge
FAKE
Firebase
Service.
js
Tests should
influence
component
design
What to not test
¡ñ server logic
¡ñ 3rd party components
¡ñ things beyond the
edges
Artist: Rene Magritte
In summary
Should we write unit tests?
YES
What matters to test?
1. Happy path 2. Behavior 3. Edge cases
What matters to not test?
Social Justice Fund is awesome
@bookstein
/donation-tracking
Be in touch
¡ñ React development & testing
¡ñ Existential questions
¡ñ Social Justice Fund
Artists featured: Alexandra Levasseur,
Andrew Baines, Edvard Munch, Rene
Magritte, Rafal Olbinski, Salvador Dali
¡ñ React development & testing
¡ñ Existential questions
¡ñ Social Justice Fund
Thanks!
@bookstein
/donation-tracking
Ad

Recommended

Javascript testing: tools of the trade
Javascript testing: tools of the trade
Juanma Orta
?
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Codemotion
?
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Matt Raible
?
Don't Leave Windows Broken
Don't Leave Windows Broken
Ken William
?
JSF Custom Components
JSF Custom Components
Michael Fons
?
React.js workshop by tech47.in
React.js workshop by tech47.in
Jaikant Kumaran
?
Mobile optimization
Mobile optimization
purplecabbage
?
Rtt preso
Rtt preso
fdschoeneman
?
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can e big
Andy Peterson
?
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
paridhiagarwal129
?
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
Paul Irish
?
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
?
Do I need tests when I have the compiler - Andrzej J¨®?wiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej J¨®?wiak - TomTom Dev Day 2020
Andrzej J¨®?wiak
?
jQuery Anti-Patterns for Performance
jQuery Anti-Patterns for Performance
Andr¨¢s Kov¨¢cs
?
Code igniter unittest-part1
Code igniter unittest-part1
Albert Rosa
?
Puppeteer - A web scraping & UI Testing Tool
Puppeteer - A web scraping & UI Testing Tool
Miki Lombardi
?
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
Nick Plante
?
Testable JavaScript: Application Architecture
Testable JavaScript: Application Architecture
Mark Trostler
?
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
Long Weekend LLC
?
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Dakiry
?
ÈíÌå²âÊÔÊÇÔÚ²âÊÔʲüN?
ÈíÌå²âÊÔÊÇÔÚ²âÊÔʲüN?
Yao Nien Chung
?
Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
vvatikiotis
?
Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
Chris B. France
?
Dev fest kyoto_2021-flutter_test
Dev fest kyoto_2021-flutter_test
Masanori Kato
?
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.
Peter Higgins
?
From devOps to front end Ops, test first
From devOps to front end Ops, test first
Caesar Chi
?
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
Johan Nilsson
?
Testing Legacy Rails Apps
Testing Legacy Rails Apps
Rabble .
?
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Philip Schwarz
?
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
?

More Related Content

Similar to An existential guide to testing React UIs (20)

Javascript unit testing, yes we can e big
Javascript unit testing, yes we can e big
Andy Peterson
?
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
paridhiagarwal129
?
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
Paul Irish
?
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
?
Do I need tests when I have the compiler - Andrzej J¨®?wiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej J¨®?wiak - TomTom Dev Day 2020
Andrzej J¨®?wiak
?
jQuery Anti-Patterns for Performance
jQuery Anti-Patterns for Performance
Andr¨¢s Kov¨¢cs
?
Code igniter unittest-part1
Code igniter unittest-part1
Albert Rosa
?
Puppeteer - A web scraping & UI Testing Tool
Puppeteer - A web scraping & UI Testing Tool
Miki Lombardi
?
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
Nick Plante
?
Testable JavaScript: Application Architecture
Testable JavaScript: Application Architecture
Mark Trostler
?
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
Long Weekend LLC
?
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Dakiry
?
ÈíÌå²âÊÔÊÇÔÚ²âÊÔʲüN?
ÈíÌå²âÊÔÊÇÔÚ²âÊÔʲüN?
Yao Nien Chung
?
Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
vvatikiotis
?
Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
Chris B. France
?
Dev fest kyoto_2021-flutter_test
Dev fest kyoto_2021-flutter_test
Masanori Kato
?
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.
Peter Higgins
?
From devOps to front end Ops, test first
From devOps to front end Ops, test first
Caesar Chi
?
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
Johan Nilsson
?
Testing Legacy Rails Apps
Testing Legacy Rails Apps
Rabble .
?
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can e big
Andy Peterson
?
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
paridhiagarwal129
?
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
Paul Irish
?
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
?
Do I need tests when I have the compiler - Andrzej J¨®?wiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej J¨®?wiak - TomTom Dev Day 2020
Andrzej J¨®?wiak
?
jQuery Anti-Patterns for Performance
jQuery Anti-Patterns for Performance
Andr¨¢s Kov¨¢cs
?
Code igniter unittest-part1
Code igniter unittest-part1
Albert Rosa
?
Puppeteer - A web scraping & UI Testing Tool
Puppeteer - A web scraping & UI Testing Tool
Miki Lombardi
?
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
Nick Plante
?
Testable JavaScript: Application Architecture
Testable JavaScript: Application Architecture
Mark Trostler
?
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
Long Weekend LLC
?
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Dakiry
?
ÈíÌå²âÊÔÊÇÔÚ²âÊÔʲüN?
ÈíÌå²âÊÔÊÇÔÚ²âÊÔʲüN?
Yao Nien Chung
?
Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
vvatikiotis
?
Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
Chris B. France
?
Dev fest kyoto_2021-flutter_test
Dev fest kyoto_2021-flutter_test
Masanori Kato
?
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.
Peter Higgins
?
From devOps to front end Ops, test first
From devOps to front end Ops, test first
Caesar Chi
?
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
Johan Nilsson
?
Testing Legacy Rails Apps
Testing Legacy Rails Apps
Rabble .
?

Recently uploaded (20)

Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Philip Schwarz
?
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
?
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
?
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
?
Digital Transformation: Automating the Placement of Medical Interns
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
?
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
?
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
?
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
?
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
?
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
NEW-IDM Crack with Internet Download Manager 6.42 Build 27 VERSION
NEW-IDM Crack with Internet Download Manager 6.42 Build 27 VERSION
grete1122g
?
Which Hiring Management Tools Offer the Best ROI?
Which Hiring Management Tools Offer the Best ROI?
HireME
?
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
?
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
?
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Philip Schwarz
?
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
?
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
?
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
?
Digital Transformation: Automating the Placement of Medical Interns
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
?
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
?
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
?
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
?
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
?
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
NEW-IDM Crack with Internet Download Manager 6.42 Build 27 VERSION
NEW-IDM Crack with Internet Download Manager 6.42 Build 27 VERSION
grete1122g
?
Which Hiring Management Tools Offer the Best ROI?
Which Hiring Management Tools Offer the Best ROI?
HireME
?
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
?
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
?
Ad

An existential guide to testing React UIs