Skip to main content

Getting Started with itdoc

itdoc is a lightweight library that helps automatically generate test code based on Jest, Mocha.js, as well as OAS documentation, Markdown, and Redocli-HTML documents using its own interface. It's ideal for developers who want to naturally create API documentation while practicing Test-Driven Development (TDD).

Installation

  1. You need Node.js 20 installed.
pnpm install itdoc --save-dev

Test Writing Example

describeAPI(
HttpMethod.POST,
"/signup",
{
summary: "User Registration API",
tag: "Auth",
description: "Registers a new user with username and password.",
},
targetApp,
(apiDoc) => {
itDoc("Successful registration", () => {
return apiDoc
.test()
.req()
.body({
username: field("username", "penekhun"),
password: field("password", "P@ssw0rd123!@#"),
})
.res()
.status(HttpStatus.CREATED)
})
},
)

Overview

itdoc is a library designed for test automation and API documentation generation. Key features include:

  • Domain-Specific Language (DSL): Provides an interface for declaratively describing test cases and API behavior.
  • Builder Pattern: Offers various builder classes like RootBuilder, RequestBuilder, and ResponseBuilder for test case composition.
  • Multiple Test Framework Support: Includes adapters (MochaAdapter, JestAdapter) to accommodate different test frameworks such as Mocha and Jest.
  • HTTP-Related Constants: Provides enumerations (HttpMethod, HttpStatus) for managing HTTP methods and status codes.

For more detailed examples, check out the examples in the GitHub repository.

What's Next?