0% found this document useful (0 votes)
317 views

Test-Driven Development with React and TypeScript: Building Maintainable React Applications 2nd Edition Juntao Qiu instant download

The document is a resource for downloading the second edition of 'Test-Driven Development with React and TypeScript' by Juntao Qiu, which focuses on building maintainable React applications. It includes links to additional recommended books on related topics such as React, TypeScript, and Test-Driven Development. The document also contains copyright information and details about the book's content and structure.

Uploaded by

lillijeikel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
317 views

Test-Driven Development with React and TypeScript: Building Maintainable React Applications 2nd Edition Juntao Qiu instant download

The document is a resource for downloading the second edition of 'Test-Driven Development with React and TypeScript' by Juntao Qiu, which focuses on building maintainable React applications. It includes links to additional recommended books on related topics such as React, TypeScript, and Test-Driven Development. The document also contains copyright information and details about the book's content and structure.

Uploaded by

lillijeikel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Test-Driven Development with React and

TypeScript: Building Maintainable React


Applications 2nd Edition Juntao Qiu pdf download

https://ebookmass.com/product/test-driven-development-with-react-
and-typescript-building-maintainable-react-applications-2nd-
edition-juntao-qiu/

Explore and download more ebooks at ebookmass.com


Here are some recommended products for you. Click the link to
download, or explore more at ebookmass.com

React and React Native - Fifth Edition Mikhail Sakhniuk

https://ebookmass.com/product/react-and-react-native-fifth-edition-
mikhail-sakhniuk/

■■■■■■ ■■ TypeScript■React■Node.js■webpack ■ Docker Frank


Zammetti

https://ebookmass.com/product/%e7%8e%b0%e4%bb%a3%e5%85%a8%e6%a0%88%e5%
bc%80%e5%8f%91-%e4%bd%bf%e7%94%a8-
typescript%e3%80%81react%e3%80%81node-
js%e3%80%81webpack-%e5%92%8c-docker-frank-zammetti/

Master React in 5 Days: Become a React Expert in Under a


Week Eric Sarrion

https://ebookmass.com/product/master-react-in-5-days-become-a-react-
expert-in-under-a-week-eric-sarrion/

Master React in 5 Days: Become a React Expert in Under a


Week Eric Sarrion

https://ebookmass.com/product/master-react-in-5-days-become-a-react-
expert-in-under-a-week-eric-sarrion-2/
Test-Driven Development in Go Simion

https://ebookmass.com/product/test-driven-development-in-go-simion/

React Hooks in Action MEAP 03 John Larsen [Larsen

https://ebookmass.com/product/react-hooks-in-action-meap-03-john-
larsen-larsen/

Hands-on Test-Driven Development: Using Ruby, Ruby on


Rails, and RSpec 1st Edition Greg Donald

https://ebookmass.com/product/hands-on-test-driven-development-using-
ruby-ruby-on-rails-and-rspec-1st-edition-greg-donald/

Hands-on Test-Driven Development: Using Ruby, Ruby on


Rails, and RSpec 1 / converted Edition Greg Donald

https://ebookmass.com/product/hands-on-test-driven-development-using-
ruby-ruby-on-rails-and-rspec-1-converted-edition-greg-donald/

Database-Driven Web Development: Learn to Operate at a


Professional Level with PERL and MySQL 2nd Edition Thomas
Valentine
https://ebookmass.com/product/database-driven-web-development-learn-
to-operate-at-a-professional-level-with-perl-and-mysql-2nd-edition-
thomas-valentine/
Test-Driven
Development with
React and TypeScript
Building Maintainable React
Applications

Second Edition

Juntao Qiu
Test-Driven
Development with
React and TypeScript
Building Maintainable React
Applications
Second Edition

Juntao Qiu
Test-Driven Development with React and TypeScript: Building
Maintainable React Applications

Juntao Qiu
Wantirna, 3152, VIC, Australia

ISBN-13 (pbk): 978-1-4842-9647-9 ISBN-13 (electronic): 978-1-4842-9648-6


https://doi.org/10.1007/978-1-4842-9648-6

Copyright © 2023 by Juntao Qiu


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Divya Modi
Development Editor: James Markham
Coordinating Editor: Divya Modi
Cover designed by eStudioCalamar
Cover image by Pixabay
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1
New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201)
348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media,
LLC is a California LLC and the sole member (owner) is Springer Science + Business Media
Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for
reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub (github.com/apress). For more detailed information, please visit
http://www.apress.com/source-code.
Paper in this product is recyclable
To Mansi and Luna.
Table of Contents
About the Author�������������������������������������������������������������������������������xiii
About the Technical Reviewers����������������������������������������������������������xv
Acknowledgments����������������������������������������������������������������������������xvii
Foreword 1����������������������������������������������������������������������������������������xix
Foreword 2����������������������������������������������������������������������������������������xxi
Introduction�������������������������������������������������������������������������������������xxiii

Chapter 1: A Brief History of Test-Driven Development������������������������1


What Is Test-Driven Development?�����������������������������������������������������������������������1
The Red-Green-Refactor Cycle������������������������������������������������������������������������2
A Closer Look at Red-Green-Refactor�������������������������������������������������������������4
Types of TDD����������������������������������������������������������������������������������������������������5
Prerequisites of TDD����������������������������������������������������������������������������������������8
Other Techniques That Can Help Implement TDD������������������������������������������������10
Tasking����������������������������������������������������������������������������������������������������������10
Summary������������������������������������������������������������������������������������������������������������12
Further Reading��������������������������������������������������������������������������������������������������12

Chapter 2: Get Started with Jest��������������������������������������������������������15


Set Up the Environment��������������������������������������������������������������������������������������15
Install and Configure Jest������������������������������������������������������������������������������16
Jest at First Glance���������������������������������������������������������������������������������������������18
Basic Concepts in Jest����������������������������������������������������������������������������������21

v
Table of Contents

Using Matchers in Jest���������������������������������������������������������������������������������������25


Basic Usages�������������������������������������������������������������������������������������������������25
Matchers for Array and Object�����������������������������������������������������������������������27
The Powerful Function expect�����������������������������������������������������������������������28
Build Your Matchers���������������������������������������������������������������������������������������31
Mocking and Stubbing����������������������������������������������������������������������������������������34
jest.fn for Spying�������������������������������������������������������������������������������������������35
Mock Implementation������������������������������������������������������������������������������������35
Stub a Remote Service Call���������������������������������������������������������������������������36
Summary������������������������������������������������������������������������������������������������������������37

Chapter 3: Refactoring Essentials: The Basics You Need to Know����39


The Ten Most Common Refactorings������������������������������������������������������������������39
Let’s Talk the Problem – Code Smells�����������������������������������������������������������������40
Long Files������������������������������������������������������������������������������������������������������40
Big Props List������������������������������������������������������������������������������������������������41
Mixing Computation with Views��������������������������������������������������������������������42
Overuse of Mocks������������������������������������������������������������������������������������������43
Not Following Established Principles������������������������������������������������������������44
The Problem – ROT13�����������������������������������������������������������������������������������������45
The Initial Implementation����������������������������������������������������������������������������������45
The Top Ten Refactorings������������������������������������������������������������������������������������47
Step 1: Slide Statements�������������������������������������������������������������������������������48
Step 2: Extract Constant��������������������������������������������������������������������������������49
Step 3: Extract Function��������������������������������������������������������������������������������50
Step 4: Rename Parameter����������������������������������������������������������������������������51
Step 5: Rename Variable�������������������������������������������������������������������������������52
Step 6: Extract Function��������������������������������������������������������������������������������53

vi
Table of Contents

Step 7: Replace if-else with ?������������������������������������������������������������������������55


Step 8: Extract Function��������������������������������������������������������������������������������56
Step 9: Extract Parameter������������������������������������������������������������������������������57
Step 10: Extract Constant������������������������������������������������������������������������������58
Step 11: Slide Statements�����������������������������������������������������������������������������59
Step 12: Move Fields�������������������������������������������������������������������������������������60
Step 13: Function to Arrow Function�������������������������������������������������������������61
Step 14: Simplify Logic����������������������������������������������������������������������������������62
Summary������������������������������������������������������������������������������������������������������������63

Chapter 4: Test-Driven Development Essentials���������������������������������65


Writing Tests�������������������������������������������������������������������������������������������������������65
Using Given-When-Then to Arrange a Test����������������������������������������������������66
Triangulation Method������������������������������������������������������������������������������������������69
Example: Function addition���������������������������������������������������������������������������69
How to Do Tasking with TDD�������������������������������������������������������������������������������72
An Expression Parser for Tracking Progress��������������������������������������������������73
Applying TDD Step by Step����������������������������������������������������������������������������75
Keep Refactoring – Extract Functions to Files�����������������������������������������������78
Summary������������������������������������������������������������������������������������������������������������80

Chapter 5: Project Setup���������������������������������������������������������������������81


Application Requirements�����������������������������������������������������������������������������������81
Feature 1 – Book List������������������������������������������������������������������������������������82
Feature 2 – Book Detail���������������������������������������������������������������������������������83
Feature 3 – Searching�����������������������������������������������������������������������������������83
Feature 4 – Book Reviews�����������������������������������������������������������������������������84

vii
Table of Contents

Create the Project�����������������������������������������������������������������������������������������������84


Using create-react-app���������������������������������������������������������������������������������84
Material UI Library�����������������������������������������������������������������������������������������88
Install Cypress�����������������������������������������������������������������������������������������������91
Commit Code to Version Control��������������������������������������������������������������������95
Summary������������������������������������������������������������������������������������������������������������96

Chapter 6: Implement the Book List���������������������������������������������������97


Acceptance Tests for Book List���������������������������������������������������������������������������97
A List (of Books)��������������������������������������������������������������������������������������������97
Verify Book Name������������������������������������������������������������������������������������������99
Refactoring – Extract Function��������������������������������������������������������������������100
Refactoring – Extract Component����������������������������������������������������������������103
Talk to the Backend Server�������������������������������������������������������������������������������105
Stub Server��������������������������������������������������������������������������������������������������106
Async Request in Application����������������������������������������������������������������������108
Setup and Teardown������������������������������������������������������������������������������������110
Adding a Loading Indicator�������������������������������������������������������������������������������114
Refactor First�����������������������������������������������������������������������������������������������114
Define a React Hook������������������������������������������������������������������������������������118
Unit Tests of the Bookish Application����������������������������������������������������������������120
Unit Test with the React Testing Library������������������������������������������������������120
Summary����������������������������������������������������������������������������������������������������������123

Chapter 7: Implementing the Book Detail View��������������������������������125


Acceptance Tests����������������������������������������������������������������������������������������������125
Link to Detail Page��������������������������������������������������������������������������������������126
Verify Book Title on Detail Page�������������������������������������������������������������������126
Frontend Routing�����������������������������������������������������������������������������������������127

viii
Table of Contents

Unit Tests����������������������������������������������������������������������������������������������������������132
Refactoring��������������������������������������������������������������������������������������������������133
Book Detail Page�����������������������������������������������������������������������������������������137
File Structure�����������������������������������������������������������������������������������������������139
Testing Data������������������������������������������������������������������������������������������������������141
User Interface Refinement��������������������������������������������������������������������������������143
Using Grid System���������������������������������������������������������������������������������������144
Handling Default Value��������������������������������������������������������������������������������������146
A Failing Test with undefined����������������������������������������������������������������������146
One Last Change?���������������������������������������������������������������������������������������������149
Summary����������������������������������������������������������������������������������������������������������150

Chapter 8: Searching by Keyword����������������������������������������������������153


Acceptance Test������������������������������������������������������������������������������������������������153
One Step Further�����������������������������������������������������������������������������������������158
What Have We Done?����������������������������������������������������������������������������������162
Moving Forward – The Test Code Is As Important���������������������������������������������163
Summary����������������������������������������������������������������������������������������������������������167

Chapter 9: Introduction to State Management���������������������������������169


State Management��������������������������������������������������������������������������������������������170
A Typical Scenario of Building UI�����������������������������������������������������������������170
Pub-Sub Pattern������������������������������������������������������������������������������������������171
A Brief of Redux�������������������������������������������������������������������������������������������172
Decoupling Data and View���������������������������������������������������������������������������174
The Formula: view = f(state)�����������������������������������������������������������������������176
Implementing State Management���������������������������������������������������������������������178
Environment Setup��������������������������������������������������������������������������������������178
Define a Slice����������������������������������������������������������������������������������������������179

ix
Table of Contents

Fetching Data from Remote�������������������������������������������������������������������������181


Define the Store�������������������������������������������������������������������������������������������183
Migrate the Application�������������������������������������������������������������������������������������185
Book List Container�������������������������������������������������������������������������������������186
Refine the SearchBox����������������������������������������������������������������������������������187
Test Individual Reducers�����������������������������������������������������������������������������������189
Book Details Slice���������������������������������������������������������������������������������������������190
Do You Need a State Management Library?������������������������������������������������������193
Summary����������������������������������������������������������������������������������������������������������194

Chapter 10: Book Reviews����������������������������������������������������������������197


Business Requirements������������������������������������������������������������������������������������198
Start with an Empty List������������������������������������������������������������������������������198
Rendering a Static List��������������������������������������������������������������������������������200
Use the Review Component in BookDetail��������������������������������������������������201
Fulfill a Book Review Form��������������������������������������������������������������������������203
End-to-End Test�������������������������������������������������������������������������������������������������205
Define a Review Slice����������������������������������������������������������������������������������207
Adjust the Stub Server for Book Reviews����������������������������������������������������209
Refactoring��������������������������������������������������������������������������������������������������214
Add More Fields������������������������������������������������������������������������������������������������216
Review Editing��������������������������������������������������������������������������������������������������220
Save a Review – Action and Reducer����������������������������������������������������������223
Integration All Together��������������������������������������������������������������������������������227
Summary����������������������������������������������������������������������������������������������������������230

x
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Table of Contents

Chapter 11: Behavior-Driven Development���������������������������������������231


Play with Cucumber������������������������������������������������������������������������������������������232
Install and Config cucumber Plugin�������������������������������������������������������������233
Live Document with cucumber�������������������������������������������������������������������������235
File Structure�����������������������������������������������������������������������������������������������235
The First Feature Specification��������������������������������������������������������������������235
Define the Steps������������������������������������������������������������������������������������������236
Book List������������������������������������������������������������������������������������������������������238
Searching����������������������������������������������������������������������������������������������������240
Review Page������������������������������������������������������������������������������������������������242
Summary����������������������������������������������������������������������������������������������������������244

Appendix A: Background of Testing Strategies��������������������������������245

Appendix B: A Short Introduction to TypeScript�������������������������������251

Index�������������������������������������������������������������������������������������������������259

xi
About the Author
Juntao Qiu is an accomplished software
developer renowned for his expertise
in producing high-quality and easily
maintainable code. He is committed to
helping individuals improve their code-
writing abilities and generously shares his vast
knowledge and experience through multiple
platforms, including books such as this one
and Maintainable React (Leanpub, 2022).
In addition, Juntao hosts a YouTube channel (@icodeit.juntao) where
he provides valuable insights, tips, and best practices for writing clean
code and performing refactoring. Juntao’s goal is to empower developers,
enabling them to reach their full potential and have a positive impact on
the software development industry.

xiii
About the Technical Reviewers
Jeff Friesen is a freelance teacher and
software developer with an emphasis on
Java. In addition to authoring Java I/O, NIO
and NIO.2 (Apress) and Java Threads and
the Concurrency Utilities (Apress), Jeff has
written numerous articles on Java and other
technologies (such as Android) for JavaWorld
(JavaWorld.com) – now InfoWorld (www.
infoworld.com/category/java/), informIT
(InformIT.com), Java.net (no longer in existence), SitePoint (SitePoint.
com), and other websites. Jeff can be contacted via his email address:
jefff@xplornet.ca.

Alexander Nnakwue has a background


in mechanical engineering and is a senior
software engineer with over seven years of
experience in various industries including
payments, blockchain, and marketing
technology. He is a published author for
professional JavaScript, a technical writer, and
a reviewer. He currently works as a software
engineer at Konecranes with the digital
experience team, working on machine data
and industrial cranes.
In his spare time, he loves to listen to music and enjoys the game of
soccer. He resides in Helsinki, Finland, with his lovely wife and son Kaobi.

xv
Acknowledgments
I am profoundly grateful to my ThoughtWorks colleagues for their
enthusiastic engagement and invaluable contributions during the
development of this book. Our project discussions were a fountain of
insight, enriching the narrative with an array of diverse perspectives. A
special acknowledgment goes to Evan Bottcher for his meticulous review
and for providing an eloquent foreword for the book.
Before embarking on the second edition, I reached out to my
newsletter (https://juntao.substack.com/) subscribers with a survey,
seeking their expectations for the new iteration. The response was
overwhelming and deeply informative – my heartfelt thanks go out to
those dedicated readers who took the time to provide their input.
I must extend my profound appreciation to the editorial team for their
indispensable support throughout the second edition’s journey. Their
expert advice has proven invaluable in refining the text, and it’s their
tireless dedication that has brought this project to fruition.
Finally, upon first sharing my book’s vision with my colleagues
at ThoughtWorks, the outpouring of valuable feedback I received –
spanning from minor typographical corrections to substantial technical
suggestions – was truly overwhelming. In particular, on a cool morning
in May 2020, I was greeted with an uplifting email from Hannah Bourke,
who not only expressed her appreciation for the book but also offered
her editing assistance as a native English speaker and fellow developer.
Her subsequent pull requests offered not just high-quality language
corrections but also insightful technical review comments from a learner’s
perspective.

xvii
Acknowledgments

Furthermore, I am indebted to Martin Fowler, a distinguished


developer and writer, who surprised me with detailed and insightful
feedback on my initial draft. Although the content of the book has
significantly evolved since that draft, the essence of his invaluable
comments is still palpably present. Heeded his advice, I’ve trimmed
nearly a quarter of the content to enhance clarity and readability,
removed unrelated code snippets from examples, and provided more
context around the code. Above all, the lesson of simplicity that I learned
from Martin has been invaluable – emphasizing a thorough exploration
of one topic at a time, rather than superficially touching upon every
possible aspect.
In summary, the journey to this book’s completion has been enriched
by the collective wisdom and support of countless individuals. Their
feedback, suggestions, and encouragement have been nothing short of
invaluable, for which I am eternally grateful.

xviii
Foreword 1
Sometimes, I find it hard to believe that it’s been more than two decades
since Kent Beck published Extreme Programming Explained including
Test-Driven Development (TDD) as a core practice. In the years since then,
the use of automated testing has become quite commonplace, something
that almost all developers are familiar with – however, the “Red-Green-­
Refactor” cycle of TDD is often missing. The reality is that building
software test first is not easy or trivial in real-world software development
and requires deliberate practice and usually someone experienced to
learn from.
At ThoughtWorks, my role is Head of Engineering – responsible for the
quality of the software that our teams produce for and with our clients.
We set a high standard for the “internal” quality of the code we produce,
wanting it to be maintainable and extensible so that it can quickly be
changed with confidence. Test-Driven Development is a default practice
in ThoughtWorks – our experience shows that the practice leads to better
software design and good confidence from a comprehensive automated
test suite.
In my years at ThoughtWorks, I’ve seen the phenomenal rise in the
importance of JavaScript and browser applications. In 2010, we advised
that the industry should treat JavaScript as a first-class language (www.
thoughtworks.com/radar/languages-and-frameworks/javascript-­
as-­a-first-class-language) on the ThoughtWorks Technology Radar,
applying all of the same engineering rigor as other platforms. As one of
the authors of the Technology Radar, I’ve seen and helped document the
explosion of tooling and frameworks in JavaScript, many of which have
been related to the area of test automation.

xix
Foreword 1

Test-Driven Development with React and TypeScript is a practical and


hands-on guide to learn TDD with React, the most prevalent browser
application framework in use today. It guides the reader through the
fundamentals of TDD with React by implementing a series of requirements
in a nontrivial example application. The book is fast-paced, so if you’re
unfamiliar with React and its friends, you’ll need to pause along the way
and do some research as the example application grows in features and
dependencies. Along the way, Juntao points out some “smells” or signs that
the approach can be improved – for example, cluttered code organization
or hard-to-maintain test data.
Read this book if you would like to learn by example from someone
who is an expert in using TDD to grow browser applications.

Evan Bottcher
March 2021

xx
Foreword 2
Landing in the middle of a React project that had very low test coverage,
in a team that had aspirations to improve it, but without a clear strategy
of how to go about it, I struggled to find resources that stepped out how to
approach testing for a frontend project. I couldn’t find a clear explanation
of how to implement Test-Driven Development for a UI, let alone
specifically for React. This book couldn’t have come at a better time.
There are a plethora of different testing methodologies and libraries
available just for React. The ones you choose will depend on many
things. This book doesn’t prescribe a particular solution but establishes
the purpose of tests in driving out specifications and suggests an overall
approach, with practical guidance and examples. Juntao provides a
holistic explanation of the purpose and implementation of Test-Driven
Development for React, demonstrating the benefits of moving testing
earlier in the process, improving the robustness and design of our code.
Juntao’s years of experience, his eagerness and passion for learning
and sharing his knowledge in a didactic way, help to make this a relevant,
practical, and engaging guide to follow and have given me confidence in
my own testing strategies.

Hannah Bourke
March 2021

xxi
Introduction
This comprehensive book is your ultimate guide to mastering Test-Driven
Development (TDD) in the context of React and TypeScript. Whether you're
a seasoned developer seeking to refine your skills or a newcomer eager to
embrace industry-standard practices, this book caters to all levels of expertise.
Spanning a wide range of topics, each chapter in this book is
thoughtfully designed to provide you with a deep understanding of TDD
principles and their application in real-world scenarios. Let's take a
glimpse into the chapters and their role in your learning journey:

Chapters 1 to 4: Setting Up the Foundation

In these early chapters, we lay the groundwork for


your TDD journey. We provide a brief history of
Test-Driven Development, allowing you to grasp
the underlying concepts and motivations. You'll
then dive into getting started with Jest, Cypress, and
the React Testing Library, equipping you with the
necessary tools to write effective tests.

Chapters 5 to 10: Implementing the Features

These chapters form the heart of the book, as we guide


you through the step-by-step implementation of key
features in our Bookish application. From building
the book list and book detail view to incorporating
search functionality, state management, and even
enabling user reviews, you'll gain invaluable hands-on
experience in applying TDD principles to build robust
and reliable React applications.

xxiii
Introduction

Chapter 11: Describing Acceptance Tests

In this final chapter, we explore the concept of


acceptance testing and introduce you to Behavior-
Driven Development (BDD). You'll learn how to
write acceptance tests that ensure your application
meets the desired behavior and satisfies stakeholder
requirements.

By following along with each chapter, you'll not only acquire the
knowledge and skills to excel in TDD but also experience the benefits
firsthand. Faster feedback cycles, improved code quality, enhanced
collaboration, and the confidence to make changes and add new features
are just a few of the advantages you'll gain.
Are you ready to embark on a transformative journey toward
becoming a more confident, efficient, and skilled developer? Test-Driven
Development with React and TypeScript: Building Maintainable React
Applications is your comprehensive companion. Let the power of TDD
guide your development process, elevate your coding skills, and lay the
foundation for a successful career in software development. Get ready to
dive in and unlock the full potential of TDD in your React projects.

xxiv
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Exploring the Variety of Random
Documents with Different Content
SCOTS WHA HAE.
BY ROBERT BURNS.

A friend of Burns states this stirring poem was written during a


frightful storm in the wilds of Glenken, in Galloway. It was written in
September, 1793.
Scots, wha hae wi’ Wallace bled,
Scots, wham Bruce has often led;
Welcome to your gory bed,
Or to victorie!
Now’s the day, and now’s the hour;
See the front o’ battle lour;
See approach proud Edward’s pow’r—
Chains and slaverie!
Wha will be a traitor-knave?
Wha can fill a coward’s grave?
Wha sae base as be a slave?
Let him turn and flee!
Wha for Scotland’s king and law
Freedom’s sword will strongly draw,
Freeman stand, or freeman fa’,
Let him follow me!
By oppression’s woes and pains!
By our sons in servile chains!
We will drain our dearest veins,
But they shall be free!
Lay the proud usurpers low!
Tyrants fall in every foe!
Liberty’s in every blow!
Let us do or die!
JERUSALEM, THE GOLDEN.
TRANSLATED FROM THE LATIN, BY JOHN M. NEALE.

Jerusalem, the golden,


With milk and honey blest!
Beneath thy contemplation
Sink heart and voice oppressed;
I know not, Oh, I know not,
What joys await me there,
What radiancy of glory,
What bliss beyond compare.
They stand, those halls of Zion,
All jubilant with song,
And bright with many an angel,
And all the martyr throng;
The Prince is ever in them,
The daylight is serene;
The pastures of the blessed
Are decked in glorious sheen.
There is the throne of David;
And there, from care released,
The shout of them that triumph,
The song of them that feast:
And they who, with their Leader,
Have conquered in the fight
Forever and forever
Are clad in robes of white.
MISCONCEPTIONS.
BY ROBERT BROWNING.

This is a spray the Bird clung to,


Making it blossom with pleasure,
Ere the high tree-top she sprung to,
Fit for her nest and her treasure.
Oh, what a hope beyond measure
Was the poor spray’s which the flying feet hung to,—
So to be singled out, built in and sung to!
This is a heart the Queen leant on
Thrilled in a minute erratic,
Ere the true bosom she bent on,
Meet for love’s regal dalmatic.
Oh what a fancy ecstatic
Was the poor heart’s, ere the wanderer went on—
Love to be saved for it, proffered to, spent on!
JOHN ANDERSON, MY JO.
BY ROBERT BURNS.

John Anderson, my jo, John,


When we were first acquent,
Your locks were like the raven,
Your bonny brow was brent;
But now your brow is beld, John,
Your locks are like the snaw;
But blessings on your frosty pow,
John Anderson, my jo.
John Anderson, my jo, John,
We clamb the hill thegither;
And monie a canty day, John,
We’ve had wi’ ane anither.
Now we maun totter down, John,
But hand in hand we’ll go,
And sleep thegither at the foot,
John Anderson, my jo.
MAID OF ATHENS, ERE WE PART.
BY LORD BYRON.

Zoè mou sas agapo.


(My life, I love thee.)
Maid of Athens, ere we part,
Give, oh, give me back my heart!
Or, since that has left my breast,
Keep it now and take the rest!
Hear my vow before I go,
Zoè mou sas agapo.
By those tresses unconfined,
Woo’d by each Ægean wind;
By those lids whose jetty fringe
Kiss thy soft cheeks’ blooming tinge;
By those wild eyes like the roe,
Zoè mou sas agapo.
By that lip I long to taste;
By that zone-encircled waist;
By all the token-flowers that tell
What words can never speak so well;
By love’s alternate joy and woe,
Zoè mou sas agapo.
Maid of Athens! I am gone:
Think of me, sweet! when alone.
Though I fly to Istambol,
Athens holds my heart and soul:
Can I cease to love thee? No!
Zoè mou sas agapo.
TO CELIA.
BEN JONSON.

Ben Jonson was born about the year 1573, at Westminster. Little is
known about his early life, but in 1597 he is found playing and
writing for “The Admiral’s Men,” and later for the “Lord Chamberlain’s
Servants.” Afterwards he stood in great favor at court, and wrote
many of his best plays during that time—the “Alchemist,” “Catiline,”
“Bartholomew Fair,” and “Epicoene.” He died in 1637, after several
years of illness, which affected his wit and brilliancy in such a
manner that many of his later plays were not heard to the end. He
is buried in Westminster Abbey. He also wrote some prose and
some of the most beautiful lyrics of the English language.
Drink to me only with thine eyes,
And I will pledge with mine;
Or leave a kiss but in the cup
And I’ll not look for wine.
The thirst that from the soul doth rise
Doth ask a drink divine;
But might I of Jove’s nectar sup,
I would not change for thine.
I sent thee late a rosy wreath,
Not so much honoring thee
As giving it a hope that there
It could not withered be;
But thou thereon didst only breathe
And sent’st it back to me;
Since when it grows, and smells, I swear,
Not of itself but thee.
A LOVER’S QUARREL.
BY AUSTIN DOBSON.

NELLIE.
If I were you, when ladies at the play, sir,
Beckon and nod, a melodrama through,
I would not turn abstractedly away, sir,
If I were you!

FRANK.
If I were you, when persons I affected,
Wait for three hours to take me down to Kew,
I would, at least, pretend I recollected,
If I were you!

NELLIE.
If I were you, when ladies are so lavish,
Sir, as to keep me every waltz but two,
I would not dance with odious Miss McTavish,
If I were you!

FRANK.
If I were you, who vow you cannot suffer
Whiff of the best—the mildest “honey-dew,”
I would not dance with smoke-consuming Puffer,
If I were you!

NELLIE.
If I were you, I would not, sir, be bitter,
Even to write the “Cynical Review”—

FRANK.
No, I should doubtless find flirtation fitter,
If I were you!

NELLIE.
Really! You would? Why, Frank, you’re quite delightful—
Hot as Othello, and as black of hue;
Borrow my fan. I would not look so frightful,
If I were you!

FRANK.
“It is the cause.” I mean your chaperon is
Bringing some well-curled juvenile. Adieu!
I shall retire. I’d spare that poor Adonis,
If I were you!

NELLIE.
Go, if you will. At once! And by express, sir!
Where shall it be? to China—or Peru?
Go. I should leave inquirers my address, sir,
If I were you!

FRANK.
No—I remain. To stay and fight a duel
Seems on the whole, the proper thing to do—,
Ah, you are strong—I would not then be cruel,
If I were you!

NELLIE.
One does not like one’s feelings to be doubted—

FRANK.
One does not like one’s friends to misconstrue—

NELLIE.
If I confess that I a wee-bit pouted?

FRANK.
I should admit that I was piqued, too.

NELLIE.
Ask me to dance! I’d say no more about it,
If I were you!
(Waltz—Exeunt.)
KUBLA KHAN.
BY SAMUEL T. COLERIDGE.

Samuel Taylor Coleridge was born at Ottery St. Mary, Devonshire


1772. He studied at Cambridge, but left without taking his degree.
In 1795 he married Sara Fricker, Southey’s sister-in-law; in the same
year he moved to Bristol. Here he published, in collaboration with
Wordsworth, the “Lyrical Ballads.” In 1798 he went to Germany on
an annuity from the Wedgewood brothers, but he soon returned to
England and lived at Keswick. Later he went to London, where he
lived at the house of Dr. Gilman and lectured on Shakespeare and
the fine arts. He died at London in 1834.
In Xanadu did Kubla Khan
A stately pleasure dome decree,
Where Alph, the sacred river, ran,
Through caverns measureless to man,
Down to a sunless sea.
So twice five miles of fertile ground
With walls and towers were girdled round;
And there were gardens bright with sinuous rills,
Where blossomed many an incense bearing tree;
And here were forests ancient as the hills,
Enfolding sunny spots of greenery.
The shadow of the dome of pleasure
Floated midway on the waves,
Where was heard the mingled measure
From the fountain and the caves.
It was a miracle of rare device,
A sunny pleasure dome with caves of ice!
A damsel with a dulcimer
In a vision once I saw;
It was an Abyssinian maid,
And on her dulcimer she played,
Singing of Mount Abora.
Could I revive within me
Her symphony and song
To such deep delight ’twould win me
That with music loud and long
I would build that dome in air—
That sunny dome! those caves of ice!
And all who heard should see them there,
And all should cry, Beware! Beware!
His flashing eyes, his floating hair!
Weave a circle round him thrice,
And close your eyes with holy dread,
For he on honey dew hath fed
And drunk the milk of Paradise.
A BALLAD UPON A WEDDING.
BY SIR JOHN SUCKLING.

Her finger was so small, the ring


Would not stay on, which they did bring,
It was too wide a peck;
And to say truth (for out it must),
It looked like the great collar (just)
About our young colt’s neck.
Her feet beneath her petticoat,
Like little mice, stole in and out,
As if they fear’d the light;
But oh, she dances such a way!
No sun upon an Easter day
Is half so fine a sight.
Her cheeks so rare a white was on,
No daisy makes comparison,
(Who sees them is undone),
For streaks of red were mingled there,
Such as are on a Catherine pear.
(The side that’s next the sun).
Her lips were red, and one was thin,
Compar’d to that was next her chin
(Some bee had stung it newly);
But (Dick) her eyes so guard her face
I durst no more upon them gaze
Than on the sun in July.
CROSSING THE BAR.
BY ALFRED TENNYSON.

Sunset and evening star


And one clear call for me!
And may there be no moaning of the bar,
When I put out to sea.
But such a tide as moving seems asleep,
Too full for sound and foam,
When that which drew from out the boundless deep
Turns again home.
Twilight and evening bell,
And after that the dark!
And may there be no sadness of farewell,
When I embark;
For tho’ from out our bourne of Time and Place
The flood may bear me far,
I hope to see my Pilot face to face
When I have crossed the bar.
JUNE.
BY JAMES RUSSELL LOWELL.

And what is so rare as a day in June?


Then, if ever, come perfect days;
Then heaven tries the earth if it be in tune,
And over it softly her warm ear lays;
Whether we look, or whether we listen,
We hear life murmur, or see it glisten;
Every clod feels a stir of might,
An instinct within it that reaches and towers,
And, groping blindly above it for light,
Climbs to a soul in grass and flowers;
The flush of life may well be seen
Thrilling back over hills and valleys;
The cowslip startles in meadows green,
The buttercup catches the sun in its chalice,
And there’s never a leaf nor a blade too mean
To be some happy creature’s palace;
The little bird sits at his door in the sun,
Atilt like a blossom among the leaves,
And lets his illumined being o’errun
With the deluge of summer it receives;
His mate feels the eggs beneath her wings,
And the heart in her dumb breast flutters and sings
He sings to the wide world and she to her nest—
In the nice ear of nature, which song is the best?
THE HARP THAT ONCE THROUGH
TARA’S HALLS.
BY THOMAS MOORE.

The harp that once through Tara’s halls


The soul of music shed,
Now hangs as mute on Tara’s walls
As if that soul were fled.
So sleeps the pride of former days,
So glory’s thrill is o’er,
And hearts that once beat high for praise
Now feel that pulse no more.
No more to chiefs and ladies bright
The harp of Tara swells;
The chord alone that breaks at night
Its tale of ruin tells.
Thus Freedom now so seldom wakes,
The only throb she gives,
Is when some heart indignant breaks,
To show that still she lives
THE BELLS OF SHANDON.
BY FRANCIS MAHONY.

Francis Sylvester Mahony, better known as Father Prout, was born in


Cork in 1804. Though he was a Jesuit priest, he was more of a
literatus than a man of God. He is the author of the famous
“Reliques of Father Prout,” which he wrote for Frazer’s Magazine.
Later he was the Rome correspondent for the Daily News and the
Paris correspondent of the Globe. He died in Paris in 1866. Among
his poems the following is the only one worth mention:
With deep affection and recollection
I often think of those Shandon bells,
Whose sounds so wild would in the days of childhood
Fling round my cradle their magic spells.
On this I ponder, where’er I wander,
And thus grow fonder, sweet Cork, of thee;
With thy bells of Shandon,
That sound so grand on
The pleasant waters of the River Lee.
I have heard bells chiming full many a clime in,
Tolling sublime in cathedral shrine;
While at a glib rate brass tongues would vibrate,
But all their music spoke naught like thine;
For memory dwelling on each proud swelling
Of thy belfry knelling its bold notes free,
Made the bells of Shandon
Sound far more grand on
The pleasant waters of the River Lee.
I have heard bells tolling “old Adrian’s mole” in,
Their thunder rolling from the Vatican,
And cymbals glorious, swinging uproarious,
In the gorgeous turrets of Notre Dame;
But thy sounds were sweeter than the dome of Peter
Flings o’er the Tiber, pealing solemnly.
O! the bells of Shandon
Sound far more grand on
The pleasant waters of the River Lee.
There’s a bell in Moscow, while on tower and kiosko
In St. Sophia the Turkman gets,
And loud in air calls men to prayer
From the tapering summit of tall minarets.
Such empty phantom I freely grant ’em,
But there’s an anthem more dear to me;
’Tis the bells of Shandon,
That sound so grand on
The pleasant waters of the River Lee.
THE GARRET.
BY W. M. THACKERAY.

The many theater-goers who were pleased with Mr. Esmond’s


comedy, “When We Were Twenty-One,” as played by the Goodwins,
may like to see the Thackeray song from which the play took its
name. It is an imitation of a poem by Beranger.
With pensive eyes the little room I view,
Where in my youth I weathered it so long,
With a wild mistress, a stanch friend or two,
And a light heart still breaking into song;
Making a mock of life and all its cares,
Rich in the glory of my rising sun,
Lightly I vaulted up four pair of stairs,
In the brave days when I was twenty-one.
Yes, ’tis a garret, let him know’t who will;
There was my bed—full hard it was and small;
My table there—and I decipher still
Half a lame couplet charcoaled on the wall.
Ye joys that Time hath swept with him away,
Come to mine eyes, ye dreams of love and fun
For you I pawned my watch how many a day,
In the brave days when I was twenty-one.
* * *
One jolly evening, when my friends and I
Made happy music with our songs and cheers,
A shout of triumph mounted up thus high,
And distant cannon opened on our ears;
We rise—we join in the triumphant strain—
Napoleon conquers—Austerlitz is won—
Tyrants shall never tread us down again,
In the brave days when I was twenty-one.
Let us begone—the place is sad and strange;
How far, far off those happy times appear;
All that I have to live I’d gladly change
For one such month as I have wasted here—
To draw long dreams of beauty, love, and power
From founts of hope that never will return,
And drink all life’s quintessence in an hour—
Give me the days when I was twenty-one!
ON A GIRDLE.
BY EDMUND WALLER.

That which her slender waist confined


Shall now my joyful temples bind:
No monarch but would give his crown
His arms might do what this hath done.
It was my heaven’s extremest sphere,
The pale which held that lovely deer:
My joy, my grief, my hope, my love
Did all within this circle move.
A narrow compass! and yet there
Dwelt all that’s good, and all that’s fair:
Give me but what this ribband bound,
Take all the rest the sun goes round.
SOLILOQUY FROM MACBETH.
BY WILLIAM SHAKSPEARE.

Tomorrow, and tomorrow, and tomorrow,


Creeps in this petty pace from day to day
To the last syllable of recorded time,
And all our yesterdays have lighted fools
The way to dusty death. Out, out, brief candle!
Life’s but a walking shadow, a poor player
That struts and frets his hour upon the stage
And then is heard no more; it is a tale
Told by an idiot, full of sound and fury,
Signifying nothing.
THE DAY IS DONE.
BY HENRY WADSWORTH LONGFELLOW.

The day is done, and the darkness


Falls from the wings of Night,
As a feather is wafted downward
From an eagle in his flight.
I see the lights of the village
Gleam through the rain and the mist,
And a feeling of sadness comes o’er me
That my soul cannot resist;
A feeling of sadness and longing
That is not akin to pain,
And resembles sorrow only
As the mist resembles the rain.
Come, read to me some poem,
Some simple and heartfelt lay,
That shall soothe this restless feeling,
And banish the thoughts of day.
Not from the grand old masters,
Not from the bards sublime,
Whose distant footsteps echo
Through the corridors of Time.
For, like strains of martial music,
Their mighty thoughts suggest
Life’s endless toil and endeavor;
And to-night I long for rest.
Read from some humbler poet,
Whose songs gushed from his heart
As showers from the clouds of summer
Or tears from the eyelids start;
Who through long days of labor
And nights devoid of ease,
Still heard in his soul the music
Of wonderful melodies.
Such songs have power to quiet
The restless pulse of care,
And come like the benediction
That follows after prayer.
Then read from the treasured volume
The poem of thy choice,
And lend to the rhyme of the poet
The beauty of thy voice.
And the night shall be filled with music,
And the cares that infest the day
Shall fold their tents, like the Arabs,
And as silently steal away.
LITTLE BREECHES.
BY JOHN HAY.

I don’t go much on religion,


I never ain’t had no show;
But I’ve got a middlin’ tight grip, sir,
On the handful o’ things I know.
I don’t pan out on the prophets,
And free-will, and that sort of thing—
But I b’lieve in God and the angels
Ever sence one night last spring.
I come into town with some turnips,
And my little Gabe come along—
No four-year-old in the county
Could beat him for pretty and strong,
Peart, and chippy, and sassy,
Always ready to swear and fight—
And I’d larnt him to chaw terbacker
Jest to keep his milk-teeth white.
The snow come down like a blanket
As I passed by Taggart’s store;
I went in for a jug of molasses
And left the team at the door.
They scared at something and started—
I heard one little squall
And hell-to-split over the prairie
Went team, Little Breeches and all.
Hell-to-split over the prairie!
I was almost froze with skeer;
But we rousted up some torches
And sarched for ’em far and near.
At last we struck hosses and wagon
Snowed under a soft, white mound,
Upsot, dead beat—but of little Gabe
No hide nor hair was found.
And here all hope soured on me,
Of my fellow-critter’s aid—
I jest flopped down on my marrow-bones,
Crotch deep in the snow and prayed.
* * *
By this, the torches was played out,
And me and Isrul Parr
Went off for some wood to a sheepfold
That he said was somewhar thar.
We found it at last, and a little shed
Where they shut up the lambs at night.
We looked in and seen them huddled thar,
So warm, and sleepy, and white,
And thar sot Little Breeches and chirped,
As peart as ever you see,
“I want a chaw of terbacker,
And that’s what the matter of me.”
How did he git thar? Angels.
He could never have walked in that storm;
They jest stooped down and toted him
To whar it was safe and warm.
And I think that saving a little child,
And fotching him to his own,
Is a durned sight better business
Than loafing around the Throne.
FLYNN OF VIRGINIA.
BY BRET HARTE.

Didn’t know Flynn—


Flynn of Virginia—
Long as he’s been ’yar?
Look’ee here, stranger
Whar hev you been?
Here in this tunnel
He was my pardner,
That same Tom Flynn—
Working together,
In wind and weather,
Day out and in.
Didn’t know Flynn!
Well, that is queer.
Why, it’s a sin,
To think of Tom Flynn—
Tom, with his cheer;
Tom, without fear—
Stranger, look ’yar!
Thar in the drift,
Back to the wall,
He held the timbers
Ready to fall;
Then in the darkness
I heard him call:
“Run for your life, Jake!
Run for your wife’s sake!
Don’t wait for me.”
And that was all
Heard in the din,
Heard of Tom Flynn—
Flynn of Virginia.
That lets me out
Here in the damp—
Out of the sun—
That ’ar derned lamp
Makes my eyes run.
Well, there—I’m done.
But, sir, when you’ll
Hear the next fool
Asking of Flynn—
Flynn of Virginia—
Just you chip in,
Say you knew Flynn;
Say that you’ve been ’yar.
WARBLE FOR LILAC-TIME.
BY WALT WHITMAN.

Warble me now for joy of lilac-time,


Sort me, O tongue and lips for nature’s sake, souvenirs of earliest
summer,
Gather the welcome signs (as children with pebbles of stringing
shells),
Put in April and May, the hylas croaking in the ponds, the elastic
air,
Bees, butterflies, the sparrow with its simple notes,
Bluebird and darting swallow, nor forget the high-hole flashing his
golden wings,
The tranquil sunny haze, the clinging smoke, the vapor,
Shimmer of waters with fish in them, the cerulean above.
All that is jocund and sparkling, the brooks running,
The maple woods, the crisp February days and the sugar making,
The robin where he hops, bright-eyed, brown-breasted,
With musical clear call at sunrise and again at sunset.
Or flitting among the trees of the apple orchard, building the nest
of his mate,
The melted snow of March, the willow sending forth its yellow-
green sprouts,
For springtime is here! The summer is here, and what is this in it
and from it?
Thou, soul, unloosen’d—the restlessness after I know not what;
Come, let us lag here no longer, let us be up and away!
O, if one could fly like a bird!
O, to escape, to sail forth as in a ship!
To glide with thee, O soul, o’er all, in all, as a ship o’er the waters;
Gathering these hints, the preludes, the blue sky, the grass, the
morning drops of dew,
The lilac-scent, the bushes with dark green heart-shaped leaves,
Wood violets, the little delicate pale blossoms called innocent
Samples and sorts not for themselves alone, but for their
atmosphere
To grace the bush I love—to sing with the birds,
A warble for joy of lilac-time.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookmasss.com

You might also like