- Prerequisites
- Installation
- Running Tests
- Generating HTML Reports
- Making HTTP Requests
- Generating Fake Data
- Additional Jest Matchers
- Usage
- Example
Ensure you have Node.js and pnpm installed. You can download them from the following links:
To install the required node modules, run:
pnpm install
npm test
to run all test
To generate HTML reports for your tests, you can use jest-html-reporters
. The configuration is already set up in jest.config.ts
.
This project uses axios
for making HTTP requests. You can find the helper functions for making GET, POST, PATCH, and DELETE requests in src/helper/apiHelper.ts
.
This project uses faker
for generating fake data. You can find an example of how to use faker
in src/helper/create.ts
.
This project uses jest-extended
for additional Jest matchers. The configuration is already set up in jest.config.ts
.
const { HttpGet, HttpPost, HttpPatch, HttpDelete } = require('../helper/apiHelper');
const { baseUrl, getEndpoint } = require('../config/config');
const { HttpGet, HttpPost, HttpPatch, HttpDelete } = require('../helper/apiHelper');
const { baseUrl, getEndpoint } = require('../config/config');
describe('API Testing Framework', () => {
test('should get all posts', async () => {
const endpoint = getEndpoint('getPosts');
const response = await HttpGet(`${baseUrl}${endpoint?.path}`);
expect(response.status).toEqual(200);
expect(response.data).toBeInstanceOf(Array);
});
});
Dependency | Use |
---|---|
Axios | Promise based HTTP client for the browser and node.js |
Faker | generate massive amounts of fake data |
uuid | Simple, fast generation of RFC4122 UUIDS. |
npm-run-all | A CLI tool to run multiple npm-scripts in parallel or sequential. |
lodash | odash makes JavaScript easier working with arrays, |
rimraf | The UNIX command rm -rf for node |
cross-env | Run scripts that use environment variables across platforms |