SlideShare a Scribd company logo
+
+ Unit Tests =
Alin Pandichi
Alin Pandichi
Open space
Coding Dojo
Bucharest Java User Group
Global Day of Coderetreat
Alin Pandichi
Open space
Coding Dojo
Bucharest Java User Group
Global Day of Coderetreat
Software developer @
Mozaic Labs
Building eventriX
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
Jest:  Capture snapshots of React trees or other 
serializable values to simplify testing and to 
analyze how state changes over time.
describe('Welcome (Snapshot)', () => {
it('Welcome renders hello world', () => {
const json = renderer.create(<Welcome />).toJSON();
expect(json).toMatchSnapshot();
});
});
Enzyme is a JavaScript testing utility for React 
that makes it easier to assert, manipulate, and 
traverse your React Components' output.
Mocha is a JavaScript test framework 
running on Node.js and in the browser.
var assert = require('assert');
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal(-1, [1,2,3].indexOf(4));
});
});
});
Chai ­ assertion library for node and 
the browser that can be paired with any 
javascript testing framework.
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
expect(tea).to.have.property('flavors').with.lengthOf(3);
Sinon.js ­ spies, stubs and mocks for 
JavaScript. Works with any unit testing 
framework.
it('makes a GET request for todo items', function () {
sinon.stub(jQuery, 'ajax');
getTodos(42, callbackFunction);
assert(jQuery.ajax.calledWithMatch({
url: '/todo/42/items'
}));
});
Other testing tools: 
● redux­mock­store ­ A mock store for testing 
your redux async action creators and 
middleware. 
● fetch­mock ­ mock http requests made using 
fetch
Istanbul – code coverage tool that works well 
with most JavaScript testing 
frameworks: tap, mocha, AVA, etc.
Unit Testing your React / Redux app (@BucharestJS)
To recap...
● I wouldn’t recommend Jest
● I’d rather use: 
Enzyme + Mocha + Chai + Sinon
● Try to test the ES6 classes rather than 
the React components
To recap...
● Writing tests after production code will 
lead you to “white­box testing”
● Writing tests before production will 
force you to think more about 
component contracts 
Questions?
@alinpandichi
Resources
http://mochajs.org/
http://chaijs.com/
http://sinonjs.org/
http://airbnb.io/enzyme/
https://istanbul.js.org/
https://github.com/arnaudbenard/redux­mock­store
http://www.wheresrhys.co.uk/fetch­mock/
https://facebook.github.io/jest/
Image resources
http://diysolarpanelsv.com/images/arrow­with­heart­in­middle­clipart­16.png
https://i1.wp.com/www.tugberkugurlu.com/Content/images/Uploadedbyauthors/w
http://1.bp.blogspot.com/­pkJqNgkmRe4/Tz0k6JUwJMI/AAAAAAAAAhU/h8byzSXB
http://paulocoelhoblog.com/wp­content/uploads/2012/06/IsayNO1.jpg

More Related Content

PPTX
Testing of React JS app
PDF
How to go about testing in React?
PDF
Meetup React Sanca - 29/11/18 - React Testing
PDF
Gatling Performance Workshop
PPTX
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
PDF
Automated Web Testing using JavaScript
PPTX
CI / CD w/ Codeception
PPTX
Protractor Tutorial Quality in Agile 2015
Testing of React JS app
How to go about testing in React?
Meetup React Sanca - 29/11/18 - React Testing
Gatling Performance Workshop
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Automated Web Testing using JavaScript
CI / CD w/ Codeception
Protractor Tutorial Quality in Agile 2015

What's hot (20)

ODP
Gatling - Stress test tool
PDF
Testing with Codeception
PDF
Automated Testing in Angular Slides
PDF
[FullStack NYC 2019] Effective Unit Tests for JavaScript
PPTX
Automated Testing using JavaScript
PPTX
JavaScript Metaprogramming with ES 2015 Proxy
PDF
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
PPTX
Test driving QML
PPTX
Lets cook cucumber !!
PDF
Никита Галкин "Testing in Frontend World"
PDF
Unit-testing and E2E testing in JS
PPTX
Unit testing hippo
ODP
Gatling
PPTX
Angular UI Testing with Protractor
PPTX
Automation using Javascript
PDF
Karate, the black belt of HTTP API testing?
PDF
Create an architecture for web test automation
PDF
Efficient JavaScript Unit Testing, May 2012
PDF
Insights on Protractor testing
PDF
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
Gatling - Stress test tool
Testing with Codeception
Automated Testing in Angular Slides
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Automated Testing using JavaScript
JavaScript Metaprogramming with ES 2015 Proxy
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Test driving QML
Lets cook cucumber !!
Никита Галкин "Testing in Frontend World"
Unit-testing and E2E testing in JS
Unit testing hippo
Gatling
Angular UI Testing with Protractor
Automation using Javascript
Karate, the black belt of HTTP API testing?
Create an architecture for web test automation
Efficient JavaScript Unit Testing, May 2012
Insights on Protractor testing
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
Ad

Similar to Unit Testing your React / Redux app (@BucharestJS) (20)

ODP
How to unit test your React/Redux app
PPTX
unit test in node js - test cases in node
PDF
Painless JavaScript Testing with Jest
PDF
An Introduction to the World of Testing for Front-End Developers
PDF
FITC Web Unleashed 2017 - Introduction to the World of Testing for Front-End ...
PDF
Developers Testing - Girl Code at bloomon
PDF
The Many Ways to Test Your React App
PDF
Workshop 23: ReactJS, React & Redux testing
PDF
Das Frontend richtig Testen – mit Jest @Developer Week 2018
PPT
JavaScript Testing: Mocha + Chai
PDF
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
PDF
Jest: Frontend Testing richtig gemacht @WebworkerNRW
PDF
Jest: Frontend Testing leicht gemacht @EnterJS2018
PDF
mocha sinon chai Dc jquery 4-24
PDF
Maximize Your JavaScript Test Automation: Top Frameworks & Best Practices
PDF
Test driven node.js
PDF
Front end testing you won't hate
PDF
Testing React Native Apps - Chain React 2023
PPT
Mocha Testing
PDF
TDD: Develop, Refactor and Release With Confidence
How to unit test your React/Redux app
unit test in node js - test cases in node
Painless JavaScript Testing with Jest
An Introduction to the World of Testing for Front-End Developers
FITC Web Unleashed 2017 - Introduction to the World of Testing for Front-End ...
Developers Testing - Girl Code at bloomon
The Many Ways to Test Your React App
Workshop 23: ReactJS, React & Redux testing
Das Frontend richtig Testen – mit Jest @Developer Week 2018
JavaScript Testing: Mocha + Chai
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing leicht gemacht @EnterJS2018
mocha sinon chai Dc jquery 4-24
Maximize Your JavaScript Test Automation: Top Frameworks & Best Practices
Test driven node.js
Front end testing you won't hate
Testing React Native Apps - Chain React 2023
Mocha Testing
TDD: Develop, Refactor and Release With Confidence
Ad

More from Alin Pandichi (12)

PDF
[Codecamp] The sorry state of frontend code
ODP
Coding Dojo - The learning remote control
PDF
The sorry state of frontend code [a talk @ Softbinator]
PDF
Behavior driven development - a recap (@ Symfony Bucharest Meetup)
PDF
The sorry state of frontend code
PDF
Covariance and contravariance. Say what?! (Agile Talks #22)
PDF
Coding Dojo - Berlin Clock - TDD
PDF
Coding Dojo - Golden Master Technique - Approval Tests - Gilded Rose Kata-
ODP
Coding Dojo - Refactoring Tennis Kata
PDF
Avatar.js
PDF
Software development - the java perspective
PDF
Java 8 - Lambdas and much more
[Codecamp] The sorry state of frontend code
Coding Dojo - The learning remote control
The sorry state of frontend code [a talk @ Softbinator]
Behavior driven development - a recap (@ Symfony Bucharest Meetup)
The sorry state of frontend code
Covariance and contravariance. Say what?! (Agile Talks #22)
Coding Dojo - Berlin Clock - TDD
Coding Dojo - Golden Master Technique - Approval Tests - Gilded Rose Kata-
Coding Dojo - Refactoring Tennis Kata
Avatar.js
Software development - the java perspective
Java 8 - Lambdas and much more

Recently uploaded (20)

PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Modernizing your data center with Dell and AMD
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPT
Teaching material agriculture food technology
PPTX
Big Data Technologies - Introduction.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
cuic standard and advanced reporting.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
GamePlan Trading System Review: Professional Trader's Honest Take
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Monthly Chronicles - July 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
Modernizing your data center with Dell and AMD
madgavkar20181017ppt McKinsey Presentation.pdf
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Sensors and Actuators in IoT Systems using pdf
cuic standard and advanced reporting.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”

Unit Testing your React / Redux app (@BucharestJS)