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

The jestTypical example of a Testsuite with Mocha, expect, ReactTestUtils and Babel


Let's see a typical example of package.json, which is using the following:

  • Mocha as a testing framework

  • Expect as an assertion library

  • ReactTestUtils to test react-based JavaScript components

  • Babel used as a transcompiler, which changes the ES6 codes into currently compatible (ES5) JavaScript code.

The example of package.json file:

"scripts": {
    "test": "mocha './src/**/*.test.js' --compilers js:babel-core/register",
  },
  "devDependencies": {
    "babel-core": "6.1.4",
    "babel-loader": "6.1.0",
    "babel-preset-es2015": "6.1.4",
    "babel-preset-react": "6.1.4",
    "babel-preset-stage-2": "6.1.2",
    "mocha": "2.3.3",
    "react-addons-test-utils": "0.14.3",
  }
}

As in the previous examples, within the script object, we keep the the test files and all the test files follow the convention of ending with the .test.js extension. Any extension for the test files can be used. For compilation from ES6 code...

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}