CodeceptJS HTTP Helper

0.0.7 · abandoned · verified Wed Apr 22

codeceptjs-http is an abandoned CodeceptJS helper that wraps the `then-request` library to facilitate making HTTP requests within CodeceptJS tests. It offers functionality to send requests and validate JSON responses against schemas. The package, currently at version 0.0.7, was last updated over six years ago and is not actively maintained, making it potentially incompatible with newer versions of Node.js or CodeceptJS. Its primary differentiation was providing a more flexible request management alternative to other HTTP helpers at the time, integrating directly into the CodeceptJS `I` object for test interactions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates configuring the HTTP helper, sending a POST request to create a user, validating the response schema, then sending a GET request to retrieve the user.

const { I } = inject();

Feature('API Tests');

BeforeSuite(() => {
  // Assume a server is running on http://localhost:3000
});

Scenario('Verify user creation and retrieve by ID', async () => {
  const userData = { name: 'John Doe', email: 'john.doe@example.com' };
  const createResponse = await I.sendRequest('/users', 'POST', {
    headers: { 'Content-Type': 'application/json' },
    json: userData
  });

  // Assuming the API returns the created user with an ID
  const createdUser = createResponse.body;
  I.expect(createResponse.statusCode).to.eql(201);
  I.expect(createdUser).to.have.property('id');
  I.seeHttpResponseHasValidJsonSchema('schemas/userCreateResponse.json', null, createdUser);

  const userId = createdUser.id;
  const getResponse = await I.sendRequest(`/users/${userId}`, 'GET');

  I.expect(getResponse.statusCode).to.eql(200);
  I.expect(getResponse.body.name).to.eql(userData.name);
  I.seeHttpResponseHasValidJsonSchema('schemas/userGetResponse.json', null, getResponse.body);
});

// Minimal codecept.conf.js for this quickstart:
// {
//    "helpers": {
//      "HTTP" : {
//        "require": "codeceptjs-http",
//        "endpoint": "http://localhost:3000"
//      },
//      "ChaiWrapper": {
//         "require": "codeceptjs-chai"
//      }
//    }
// }

view raw JSON →