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
Explore 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
Getting Started with React

You're reading from   Getting Started with React A light but powerful way to build dynamic real-time applications using ReactJS

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher
ISBN-13 9781783550579
Length 212 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Danillo Corvalan Danillo Corvalan
Author Profile Icon Danillo Corvalan
Danillo Corvalan
 Sengupta Sengupta
Author Profile Icon Sengupta
Sengupta
 Singhal Singhal
Author Profile Icon Singhal
Singhal
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Testing in JavaScript using Chai and Mocha


As discussed earlier, in order to write test cases for the React code, we will be installing some testing libraries to run tests and write assertions. Let's walk through the setup for the Chai assertion library and the Mocha testing framework. We need to install the libraries with the help of npm.

In the terminal type:

npm i -D mocha chai

Note

install shortform: i

devDependencies shortform: D (the package will be installed only in a development environment)

After the Chai and Mocha libraries are installed by the previously mentioned command, they can be found under the node_modules directory.

We need to add the Mocha and Chai entries in our package.json file.

Package.json code

{
  "name": "JSApp",
  "version": "1.0.0",
  "description": "Get random numbers",
  "main": "index.js",
  "scripts": {
    "test": "mocha test.js"
  },
  "devDependencies": {
    "chai": "3.2.0",
    "mocha": "2.2.5"
  }
}

According to https://docs.nodejitsu.com/articles/getting-started...

lock icon The rest of the chapter is locked
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Getting Started with React
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 $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon