An open API service indexing awesome lists of open source software.

https://github.com/shreyasdankhade/api-testing-via-jest

A comprehensive Jest-based framework for efficient and reliable API testing in Node.js applications.
https://github.com/shreyasdankhade/api-testing-via-jest

api apitesting html javascript jest jest-tests js json nodejs postman supertest

Last synced: 11 months ago
JSON representation

A comprehensive Jest-based framework for efficient and reliable API testing in Node.js applications.

Awesome Lists containing this project

README

          

# 🚀 API Testing via Jest

This repository provides a professional demonstration of API testing using Jest, a robust JavaScript testing framework. It focuses on verifying the functionality and reliability of APIs within a Node.js environment, offering structured examples and practical guidance for effective testing.

---

## 🛠️ Technologies Used

- **Node.js:** JavaScript runtime environment for backend development.
- **Jest:** A powerful JavaScript testing framework to structure and execute tests.
- **Supertest:** Library for testing HTTP endpoints efficiently.

---

## 📂 Project Structure

```
API-Testing-via-JEST/
├── MAIN.postman_collection.json # Postman collection for manual API testing
├── README.md # Project documentation
├── exam_trade.test.js # Jest tests for trade API endpoints
├── jest.config.js # Jest configuration settings
├── job_post.test.js # Jest tests for job posting API endpoints
├── test-report.html # HTML report generated by Jest
└── token.js # Token management script for authentication
```

---

## ✅ Prerequisites

Before setting up the project, ensure you have:

- [Node.js](https://nodejs.org/) (version 14.x or higher)
- [npm](https://www.npmjs.com/)

---

## ⚙️ Setup Instructions

### 1. Clone the Repository

```bash
git clone https://github.com/ShreyasDankhade/API-Testing-via-JEST.git
cd API-Testing-via-JEST
```

### 2. Install Dependencies

```bash
npm install
```

### 3. Run Tests

Execute Jest test suites using:

```bash
npm test
```

---

## 🔍 Writing and Executing Tests

### Example Jest Test

```javascript
const request = require('supertest');
const app = require('../src/app');

describe('API endpoint tests', () => {
test('GET /api should return status 200', async () => {
const response = await request(app).get('/api');
expect(response.statusCode).toBe(200);
});
});
```

---

## 🎯 Best Practices

- **Modularity**: Structure tests clearly to enhance readability and maintenance.
- **Isolation**: Use mocking to isolate tests from external dependencies.
- **Clear Descriptions**: Provide meaningful test case descriptions for easier debugging.
- **Regular Testing**: Automate test runs to detect and resolve issues promptly.

---

## 📚 Resources

- [Jest Documentation](https://jestjs.io/docs/getting-started)
- [Supertest Guide](https://github.com/visionmedia/supertest)
- [Node.js Documentation](https://nodejs.org/en/docs/)

---

## 👥 Contributors
- **Shreyas Dankhade** (Repository Owner)
- Contributions are welcome! Feel free to fork and submit pull requests.

---

## 📧 Contact
For questions or support, contact Shreyas Dankhade at shreyasdankhade75@gmail.com.