Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Redux Quick Start Guide
Redux Quick Start Guide

Redux Quick Start Guide: A beginner's guide to managing app state with Redux

Arrow left icon
Profile Icon Lee Profile Icon Kumar Mukhiya Profile Icon Wei
Arrow right icon
$15.99 $22.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (1 Ratings)
eBook Feb 2019 204 pages 1st Edition
eBook
$15.99 $22.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Lee Profile Icon Kumar Mukhiya Profile Icon Wei
Arrow right icon
$15.99 $22.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (1 Ratings)
eBook Feb 2019 204 pages 1st Edition
eBook
$15.99 $22.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$15.99 $22.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Redux Quick Start Guide

Testing

The general software development paradigm includes planning, analysis, design, implementation, and maintenance. During any software development process, it is challenging, but required, to build efficient and error-free software. Making software error-free requires rigorous inspection, testing, dry running, and debugging. Making any web application error-free is intractable. However, empirical studies have revealed that testing in web application development can sometimes be exhaustive. There are a multitude of JavaScript frameworks that can be used for unit testing. In this chapter, we will use Jest, which is a testing framework from Facebook.

The main topics that will be covered in this chapter are as follows:

  • Setting up Jest
  • Understanding how to test ES6 components
  • Exploring snapshot testing for React components
  • Testing Redux and its components
...

Setting up Jest

Setting up Jest is pretty straightforward and painless. You can access the entire code used in this chapter in the GitHub repository, inside of the CH02 folder. However, we suggest that you get started with an empty folder and walk through the hands-on tutorial, in order to get familiar with the process.

  1. Create the project and initialize it with YARN.

Create an empty folder and initialize it with YARN or npm. In this book, we will use YARN, but feel free to explore. To initialize the project, open a Terminal of your choice and run the following commands:

mkdir CHO2
cd CHO2
yarn init
Galaxy-A7-2017:CH02 sureshkumarmukhiyahvl$ yarn init
yarn init v1.12.1
question name (CH02): testing-redux-application
question version (1.0.0):
question description: Testing React and Redux applications
question entry point (index.js):
question repository url:
question author: Suresh Kumar...

Testing ES6 functions

Testing ES6 functions is pretty straightforward. Let's consider a function that calculates the total bill for a person when the hourly rate and the number of hours are provided. Save the snippet in a file called something like calculateBill.js.

Testing a function

Let's consider the following function, calculateBill. It takes totalHours and ratePerHours as the arguments, and returns the total bill:

const calculateBill = (totalHours, ratePerHours) => totalHours * ratePerHours;
module.exports = calculateBill;

To test, it let us create a file and call it calculateBill-test.js:

const calculateBill = require("../calculateBill");
test("calculate bills when the number of hours...

Testing React components

React components and mocking components

Let's consider a React component, as shown in the following code and in the file Header.js:

import React from "react";
import Link from "react-router-dom/Link";
const Header = () => (
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">Services</Link>
</li>
<li>
<Link to="/topics">Contact Us</Link>
</li>
<li>
<Link to="/topics...

Testing Redux

Let's add Redux to our project, in order to test it. You already know how to add JavaScript dependencies as follows:

yarn add react-redux--exact

Testing action creators

Action creators are pretty easy to test. We already explored what action creators are and how to use them in Chapter 1, Understanding Redux. As a reminder, in Redux, action creators are simply functions that return plain objects. Nothing complicated, right? Let's consider an action creator from our health application. We just made a function called addNewDoctor that takes new doctor data and returns the plain object, as follows:

export function addNewDoctor(newDoctorData) {
return {
type: "ADD_NEW_DOCTOR",
newDoctorData...

Summary

Test-driven development (TDD) is an emerging software development approach in the current software development process. This approach ensures building a tested application that is easier to debug and maintain in the long run. In this chapter, we explored how we can use the Jest testing framework from Facebook to test our application. We discussed how we can test ES6 components, React components, and Redux components with Jest.

We recommend that the readers follow the TDD approach in their development paradigms. With this in mind, we are going to test our components in each chapter, using the information that we covered in this lesson. In Chapter 3, Routing, we will explore how Redux can amalgamate with React components to facilitate building a data-driven application.

Further reading

The following is a list of recommended reading:

  • React and React Native, Second Edition, Adam Boduch, Packt Publications
  • React 16 – The Complete Guide (including React Router 4 and Redux) [Video], Maximilian Schwarzmüller, Packt Publications
  • Learning React with Redux and Flux [Video], Sam Slotsky, Packt Publications
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Get better at building web applications with state management using Redux
  • Learn the fundamentals of Redux to structure your app more efficiently
  • This guide will teach you develop complex apps that would be easier to maintain

Description

Starting with a detailed overview of Redux, we will follow the test-driven development (TDD) approach to develop single-page applications. We will set up JEST for testing and use JEST to test React, Redux, Redux-Sage, Reducers, and other components. We will then add important middleware and set up immutableJS in our application. We will use common data structures such as Map, List, Set, and OrderedList from the immutableJS framework. We will then add user interfaces using ReactJS, Redux-Form, and Ant Design. We will explore the use of react-router-dom and its functions. We will create a list of routes that we will need in order to create our application, and explore routing on the server site and create the required routes for our application. We will then debug our application and integrate Redux Dev tools. We will then set up our API server and create the API required for our application. We will dive into a modern approach to structuring our server site components in terms of Model, Controller, Helper functions, and utilities functions. We will explore the use of NodeJS with Express to build the REST API components. Finally, we will venture into the possibilities of extending the application for further research, including deployment and optimization.

Who is this book for?

This book is meant for JavaScript developers interesting in learning state management and building easy to maintain web applications.

What you will learn

  • Follow the test-driven development (TDD) approach to develop a single-page application
  • Add important middleware, such as Redux store middleware, redux-saga middleware, and language middleware, to your application
  • Understand how to use immutableJS in your application
  • Build interactive components using ReactJS
  • Configure react-router-redux and explore the differences between react-router-dom and react-router-redux
  • Use Redux Dev tools to debug your application
  • Set up our API server and create the API required for our application

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 28, 2019
Length: 204 pages
Edition : 1st
Language : English
ISBN-13 : 9781789806342
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Feb 28, 2019
Length: 204 pages
Edition : 1st
Language : English
ISBN-13 : 9781789806342
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 120.97
React Design Patterns and Best Practices
$43.99
React Material-UI Cookbook
$43.99
Redux Quick Start Guide
$32.99
Total $ 120.97 Stars icon

Table of Contents

9 Chapters
Understanding Redux Chevron down icon Chevron up icon
Testing Chevron down icon Chevron up icon
Routing Chevron down icon Chevron up icon
The Concept of Immutability Chevron down icon Chevron up icon
React with Redux Chevron down icon Chevron up icon
Extending Redux with Middleware Chevron down icon Chevron up icon
Debugging Redux Chevron down icon Chevron up icon
Understanding the REST API Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(1 Ratings)
5 star 0%
4 star 0%
3 star 100%
2 star 0%
1 star 0%
Chico W Sep 01, 2021
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I really wanted this book to be great. I needed a reference on redux and redux-saga. Unfortunately, this book is all over the place, introducing concepts unrelated to redux. There are a few valuable concepts presented, but not enough for me to recommend this book to anyone.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.