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
Understanding Forklifts - TECH EHS Solution
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Transform Your Business with a Software ERP System
PDF
System and Network Administration Chapter 2
PPTX
history of c programming in notes for students .pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Nekopoi APK 2025 free lastest update
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
System and Network Administraation Chapter 3
PDF
Digital Strategies for Manufacturing Companies
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Essential Infomation Tech presentation.pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
top salesforce developer skills in 2025.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
Understanding Forklifts - TECH EHS Solution
Reimagine Home Health with the Power of Agentic AI​
Transform Your Business with a Software ERP System
System and Network Administration Chapter 2
history of c programming in notes for students .pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Nekopoi APK 2025 free lastest update
Navsoft: AI-Powered Business Solutions & Custom Software Development
Design an Analysis of Algorithms II-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Wondershare Filmora 15 Crack With Activation Key [2025
wealthsignaloriginal-com-DS-text-... (1).pdf
System and Network Administraation Chapter 3
Digital Strategies for Manufacturing Companies
Upgrade and Innovation Strategies for SAP ERP Customers
Essential Infomation Tech presentation.pptx
Softaken Excel to vCard Converter Software.pdf
top salesforce developer skills in 2025.pdf
CHAPTER 2 - PM Management and IT Context

Intro to front-end testing