Skip to content

Latest commit

 

History

History

Jest

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Jest - Unit Testing In React

npm i -D Jest

Create Your File

touch nameOfFile.js

Create Your Your Second JS File and Jest will automatically know this is the testing file

touch nameOfFile.test.js

To Run the Test In Your Package.json Replace the value for the key test to simply jest under your scripts

"scripts": {
    "test": "jest"
},

Now If You Have the above configuration all you have to do is run the command

npm test

ToBe Vs. ToEqual

  • ToBe used for Primitive Types: num, string
  • ToEqual Used For Objects/Array(Reference Types)

I will use Axios for my http client

npm i axios