A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nock/openapi below:

nock/openapi: @nock/openapi is a library for mocking HTTP requests based on OpenAPI 3.x specifications. It ensures your mocks align with your API contract, providing type safety and schema validation for both requests and responses. Inspired by OpenAPI-msw.

@nock/openapi is a library for mocking HTTP requests based on OpenAPI 3.x specifications. It simplifies testing by ensuring your mocks align with your API contract.

Inspired by OpenAPI-msw

pnpm install @nock/openapi
import { loadOpenApiSpec } from "@nock/openapi";
import type { paths } from './fixtures/schema.ts'; // Generated wit openapi-typescript

it('should mock a response body according to OpenAPI spec', async () => {
  const spec = await loadOpenApiSpec<paths>(exampleSwagger, 'https://petstore3.swagger.io')

  spec.get('/store/order/123')
    .reply(200, { id: 123 }, {
      'Content-Type': 'application/json'
    });
  const response = await fetch('https://petstore3.swagger.io/store/order/123')


  expect(response.status).toBe(200)
  expect(await response.json()).toEqual({
    id: 123,
    petId: 198772,
    quantity: 7,
    shipDate: "2019-08-24T14:15:22Z",
    status: "approved",
    complete: true,
  })
})

This project is licensed under the MIT License.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4