SlideShare a Scribd company logo
Intro to
front-end testing
SpaceStation
2018
by @kangax
Current stack
React
Redux
redux-thunk
CSS components
Radium
Chrome-only
Intro to front-end testing
Majority of tests
in SpaceStation
* React
components

* Basic structural
correctness

* Simple behaviour
correctness

* Non-visual style
correctness
Intro to front-end testing
Assertions library
Assertions library
Test runner
Assertions library
Test runner
React test utils
Assertions library
Test runner
React test utils
Mocking utils
Assertions library
Test runner
React test utils
Mocking utils
Assertions library
Test runner
React test utils
Mocking utils
Assertions library
Test runner
React test utils
Mocking utils
Assertions library
Test runner
React test utils
Mocking utils
Structural testing
minMaxInput.jsx
Structural testing
minMaxInput-test.jsx
Enzyme renderer
Source file
Fake props
Render component
Structural testing
minMaxInput-test.jsx
Test case (jasmine)
Expectation (jasmine)
Test content (enzyme)
Behavioural testing
minMaxInput.jsx
Validates value
Ensures min < max
Calls onChange prop
Behavioural testing
minMaxInput-test.jsx
Find input
Simulate change event
with a specific value
Check onChange prop was called
Check correct values were set
Jest snapshots
Avatar component
Jest snapshots
Check text contains
user initials
Before
Jest snapshots
Check text contains
user initials
Before
After
Jest snapshots
Structural correctness
avatar-test.jsx.snap
Jest snapshots
Style correctness
avatar-test.jsx.snap
Jest snapshots
Props correctness
avatar-test.jsx.snap
Choose your poison
Renders in virtual DOM Renders in a real browser
Faster (~30sec) Slower (~100sec)
No virtual display req. Needs virtual display
Snapshot support No snapshot support
Testing Redux
Testing Redux
Abstraction.

Connects props to store
via selectors
Abstraction.

Connects props to actions
(potentially thunks)
Abstraction.

Checks auth in store, uses
router
Problem
Testing Redux
Our abstraction for testing
connected components
Middleware
Fake props w. spies
Actual mounting of
component w. middleware,
props, and store
Solution
Testing Redux
Mount component w.
specific "store" values
Ensure deeply nested
component is rendered
Check prop value
Mini redux store
Solution
Testing Redux
Passes in mocked store
A sprinkle of Formsy
Creates wrappers for
enzyme methods and
injects the above
concoction
Some localisation "magic"
A bit more router "magic",
for good measure
Solution
Unit test coverage
Istanbul
coveralls.io
Jest + lcov
Acceptance tests
Acceptance tests
* Actual browser launched
* Can test entire workflows
* Naturally slow
* Flakey tests; data inconsistency
* Currently non-maintained
* Very important to have
Acceptance tests
Acceptance tests
Acceptance tests
Visual regression testing
screener.io
Visual regression testing
Percy
Visual regression testing
Percy
Later instalments
* Testing connected components vs. reducers & actions
independently
* Working w. spies, mocks, stubs (Sinon, Jest)
* Working w. Faker for generating random data
* Making snapshots of connected components
TBD
* Faking timers and promises w. Sinon & Jest
Further reading
Testing in Spacestation
https://github.com/WeConnect/spacestation-v2/blob/master/TESTING.md
Getting started with Jest
https://facebook.github.io/jest/docs/en/getting-started.html
Puppeteer
https://github.com/GoogleChrome/puppeteer
Cypress
https://github.com/cypress-io/cypress
Unit testing redux connected components
https://hackernoon.com/unit-testing-redux-connected-components-692fa3c4441c
Sinon (mocks, stubs, spies)
https://github.com/sinonjs/sinon
Enzyme
http://airbnb.io/enzyme/

More Related Content

PPTX
Angular Unit Test
PPTX
Angular Unit Testing
PDF
[FullStack NYC 2019] Effective Unit Tests for JavaScript
PDF
Das Frontend richtig Testen – mit Jest @Developer Week 2018
PDF
Client side unit tests - using jasmine & karma
PDF
Angular Unit Testing from the Trenches
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
PPTX
Testing React Applications
Angular Unit Test
Angular Unit Testing
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Client side unit tests - using jasmine & karma
Angular Unit Testing from the Trenches
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Testing React Applications

What's hot (20)

PDF
Unit-testing and E2E testing in JS
PDF
Angular Unit Testing NDC Minn 2018
PDF
Mastering PowerShell Testing with Pester
PDF
Arquillian: Effective tests from the client to the server
PPTX
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
PDF
Arquillian : An introduction
PDF
Karma - JS Test Runner
PPTX
Karate for Complex Web-Service API Testing by Peter Thomas
PPTX
Angular Unit Testing
PDF
Karate, the black belt of HTTP API testing?
PPTX
Legacy Dependency Killer - Utah Code Camp 2014
PDF
Into The Box 2018 | Assert control over your legacy applications
PDF
OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagran...
PPTX
Automated Infrastructure Testing
KEY
Unit Test Your Database
PPTX
RSpec and Rails
PDF
Resilience testing with Wiremock and Spock
PPT
Integration testing
PDF
Karate - powerful and simple framework for REST API automation testing
PPTX
A Deep Dive into the W3C WebDriver Specification
Unit-testing and E2E testing in JS
Angular Unit Testing NDC Minn 2018
Mastering PowerShell Testing with Pester
Arquillian: Effective tests from the client to the server
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
Arquillian : An introduction
Karma - JS Test Runner
Karate for Complex Web-Service API Testing by Peter Thomas
Angular Unit Testing
Karate, the black belt of HTTP API testing?
Legacy Dependency Killer - Utah Code Camp 2014
Into The Box 2018 | Assert control over your legacy applications
OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagran...
Automated Infrastructure Testing
Unit Test Your Database
RSpec and Rails
Resilience testing with Wiremock and Spock
Integration testing
Karate - powerful and simple framework for REST API automation testing
A Deep Dive into the W3C WebDriver Specification
Ad

Similar to Intro to front-end testing (20)

PDF
Extreme
ODP
RichFaces - Testing on Mobile Devices
PPTX
Testing
PDF
Heavenly hell – automated tests at scale wojciech seliga
ODP
Testing In Java4278
ODP
Testing In Java
PPTX
Java script unit testing
PDF
Rethinking Testing
PPT
Unit testing with Spock Framework
PPT
Integration and Acceptance Testing
PDF
Unit Testing with Jest
ODP
Rtt preso
PDF
Javascript tdd byandreapaciolla
PDF
Jest: Frontend Testing richtig gemacht @WebworkerNRW
KEY
Javascript unit testing, yes we can e big
PDF
Continuous Delivery - Devoxx Morocco 2016
PDF
The Many Ways to Test Your React App
PDF
Behaviour driven infrastructure
PDF
Testing untestable code - DPC10
PDF
Workshop 23: ReactJS, React & Redux testing
Extreme
RichFaces - Testing on Mobile Devices
Testing
Heavenly hell – automated tests at scale wojciech seliga
Testing In Java4278
Testing In Java
Java script unit testing
Rethinking Testing
Unit testing with Spock Framework
Integration and Acceptance Testing
Unit Testing with Jest
Rtt preso
Javascript tdd byandreapaciolla
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Javascript unit testing, yes we can e big
Continuous Delivery - Devoxx Morocco 2016
The Many Ways to Test Your React App
Behaviour driven infrastructure
Testing untestable code - DPC10
Workshop 23: ReactJS, React & Redux testing
Ad

More from Juriy Zaytsev (6)

PDF
Interactive web with Fabric.js @ meet.js
KEY
printio
PDF
Fabric.js @ Falsy Values
KEY
Fabric.js — Building a Canvas Library
KEY
Say Hello To Ecmascript 5
PDF
Prototype UI Intro
Interactive web with Fabric.js @ meet.js
printio
Fabric.js @ Falsy Values
Fabric.js — Building a Canvas Library
Say Hello To Ecmascript 5
Prototype UI Intro

Recently uploaded (20)

PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Understanding Forklifts - TECH EHS Solution
PDF
top salesforce developer skills in 2025.pdf
PPTX
assetexplorer- product-overview - presentation
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Digital Strategies for Manufacturing Companies
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Introduction to Artificial Intelligence
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Cost to Outsource Software Development in 2025
PPTX
Transform Your Business with a Software ERP System
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Understanding Forklifts - TECH EHS Solution
top salesforce developer skills in 2025.pdf
assetexplorer- product-overview - presentation
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Navsoft: AI-Powered Business Solutions & Custom Software Development
Digital Strategies for Manufacturing Companies
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Design an Analysis of Algorithms I-SECS-1021-03
Introduction to Artificial Intelligence
Reimagine Home Health with the Power of Agentic AI​
Odoo Companies in India – Driving Business Transformation.pdf
Cost to Outsource Software Development in 2025
Transform Your Business with a Software ERP System
Softaken Excel to vCard Converter Software.pdf
CHAPTER 2 - PM Management and IT Context
How to Choose the Right IT Partner for Your Business in Malaysia
Upgrade and Innovation Strategies for SAP ERP Customers

Intro to front-end testing