Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Mastering React Test-Driven Development

You're reading from   Mastering React Test-Driven Development Build rock-solid, well-tested web apps with React, Redux and GraphQL

Arrow left icon
Product type Paperback
Published in May 2019
Publisher Packt
ISBN-13 9781789133417
Length 496 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Daniel Irvine Daniel Irvine
Author Profile Icon Daniel Irvine
Daniel Irvine
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface
Who this book is for
What this book covers
To get the most out of this book
Get in touch
1. First Steps with Test-Driven Development FREE CHAPTER 2. Test-driving Data Input with React 3. Exploring Test Doubles 4. Creating a User Interface 5. Humanizing Forms 6. Filtering and Searching Data 7. Test-driving React Router 8. Test-driving Redux 9. Test-driving GraphQL 10. Building a Logo Interpreter 11. Adding Animation 12. Working with WebSockets 13. Writing Your First Acceptance Test 14. Adding Features Guided by Acceptance Tests 15. Understanding TDD in the Wider Testing Landscape

Adding better wait support

Many of our step definitions contain waits that pause our test script interaction with the browser while we wait for the animations to finish. Here's an example from our tests, which waits for a period of three seconds:

await this.getPage('user').waitFor(3000);

Unfortunately, this kind of wait is brittle as there are likely to be occasions when the timeout is slightly too short and the animation hasn't finished. In this case, the test will intermittently fail. Conversely, the wait period is actually quite long. As more tests are added, the timeouts add up and the test runs suddenly take forever to run.

What we can do instead is modify our production code to alert us when it is animating. We do this by adding an isAnimating class to the viewport div when an animation is running. We then use the Puppeteer waitForSelector function...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime
Banner background image