https://github.com/zakimohammed/ms-jest
JEST project for MS training.
https://github.com/zakimohammed/ms-jest
jest node-jest unit-testing
Last synced: 2 months ago
JSON representation
JEST project for MS training.
- Host: GitHub
- URL: https://github.com/zakimohammed/ms-jest
- Owner: ZakiMohammed
- Created: 2024-10-24T03:00:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-24T03:06:00.000Z (over 1 year ago)
- Last Synced: 2025-04-06T00:43:17.212Z (about 1 year ago)
- Topics: jest, node-jest, unit-testing
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JEST - Delightful JavaScript Test Framework
JEST project for MS training.
#### Topics Covered
- Initial Setup
- Test Specs and Suites
- Matchers
- Spying and Mocking
- Third-Party Packages
- Commands and Coverage
Checkout the trend: https://npmtrends.com/chai-vs-jasmine-vs-jest-vs-mocha-vs-sinon
Checkout the JEST: https://jestjs.io/
#### Install JEST
```
npm i jest
npm i @types/jest
```
#### Creating Script in package.json
```
"scripts": {
"test": "jest",
}
```
#### Creating a Function
sum.js
```
const sum = (num1, num2) => num1 + num2
module.exports = sum
```
#### Writing Test Case
sum.test.js
```
const sum = require('./sum')
test('should add num 1 and num 2', () => {
expect(sum(10, 20)).toBe(30)
})
```
#### Execute Test Cases
```
npm test
> jest@1.0.0 test
> jest
PASS basics/sum.test.js
√ should add num 1 and num 2 (2 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.666 s, estimated 1 s
Ran all test suites.
```
#### Extra Scripts
```
"scripts": {
"test": "jest",
"test:watch": "jest --watchAll",
"test:verbose": "jest --verbose",
"test:coverage": "jest --coverage",
"test:all": "jest --watchAll --verbose --coverage",
}
```
#### Extra Executes
```
npm test
npm run test:watch
npm run test:verbose
npm run test:coverage
npm run test:all
```