- The
data-structure.jsfile - A simple implementation of blockchain structure - The
Hashing.jsfile - A function of algorithm to find position of a Substring - The
mock-function-demo.jsfile - A simple demo of Jest Mock Function - The
setup-teardownfolder - A folder of test files using Jest Setup and Teardown Functions Unit Test filesusing Jest framework
- Getting started with Jest
- Testing JS algorithm using JEST framework
- Testing JS data structure using JEST framework
- Setup - teardown demo in JEST
- Mock function demo in JEST
- Testing React using JEST framework
Make sure you have Node installed on your system If your project does not have package.json file, run the following command first:
npm init -y
Install Jest using yarn:
yarn add --dev jest
Or npm:
npm install --save-dev jest
Add the following section to your package.json:
{
"scripts": {
"test": "jest"
}
}
Finally, run yarn test or npm test after preparing unit code and test file to see the test result
You will find in this session:
-
A simple problem will be solved by Hash algorithm, and we will use JEST to test the accuracy of it
-
Steps to test:
- Using Brute Force algorithm to create test case and correct answer
- Using test case to test Hash algorithm
- See the test result
View more explanation and details code in algorithm.md
You will find in this session:
- A simple implementation of blockchain structure. If you want to get more details to the blockchain, find out at: BlockChain details
- Test cases to test the blockchain created with JEST framework:
- A new block added must have hash matching difficulty
- A new block added must have prevHash matching the hash of last block of blockchain
- A new block added must have data immutable
- Not changing any data, the whole blockchain should return valid status
- Changing data of block 1 only, The whole blockchain should return invalid status
- Changing data and hash of block 1, The whole blockchain should return invalid status
View more explanation and details code in data-structure.md
You will find in this session:
-
A simple implementation of Jest Setup and Teardown Functions, which help to set up some work that needs to happen before tests run and some work that needs to happen after tests run.
-
Test cases with cities database and food database later too see how to advoid calling init() and clear() method at the begining and at the end of each of these test
- A repeating setup for 3 test
- A one-time setup - declare once and using for all class test
- Describe - testing class inside describe block only.
- Order of testing is situation include all beforeEach(), afterEach(), beforeAll(), afterAll() and describe block
- One more order of execution.
You will find in this session:
-
A simple implementation of calling another function to retrieve data from database, which points out the problem why we should apply mock function in unit testing
-
2 ways of creating mock function in JEST
- Conducting a manual mock function by overriding the original one
- JEST framework supports us an operation to create mock function, which can mock implementation or mock the return value


