Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with React

You're reading from  Getting Started with React

Product type Book
Published in Apr 2016
Publisher
ISBN-13 9781783550579
Pages 212 pages
Edition 1st Edition
Languages
Authors (3):
Doel Sengupta Doel Sengupta
Profile icon Doel Sengupta
Manu Singhal Manu Singhal
Profile icon Manu Singhal
Danillo Corvalan Danillo Corvalan
Profile icon Danillo Corvalan
View More author details

Table of Contents (18) Chapters

Testing using ReactTestUtils


ReactTestUtils is used to test React-based components. It can simulate all the JavaScript-based events, which ReactJS supports. The documentation is cited in the Facebook developer site (https://facebook.github.io/react/docs/test-utils.html).

The code is as shown for the stimulate function:

Simulate.{eventName}(
  DOMElement element,
  [object eventData]
)

Installing React and JSX

As mentioned earlier, while installing the Chai and mocha, we are here installing React- and JSX-specific test tools (ReactTestUtils) in order to ease our task. Let's explore the ReactTestUtils with help from some React-based components and stimulate them to test the behavior and functionality.

The following is an example of such a code.

We need to install the jest package via npm with the following code in the terminal:

sudo npm install jest-cli –save-dev

sudo/root access to the machine/server where the node packages has to be installed is required. This is particularly required as the directory...

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}