Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nrk/expect-openapi

Package Overview
Dependencies
Maintainers
144
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nrk/expect-openapi

Expect objects to match OpenAPI documents

  • 2.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47
increased by17.5%
Maintainers
144
Weekly downloads
 
Created
Source

expect-openapi npm

Expect objects to match OpenAPI documents

Setup

yarn add -D @nrk/expect-openapi
# or
npm add --dev @nrk/expect-openapi

jest.setup.ts:

import { toMatchApiResponse, toMatchRef$ } from "@nrk/expect-openapi";
import expect from "expect";
expect.extend({ toMatchApiResponse, toMatchRef$ });

update the jest config:

setupFiles: ["<rootDir>/jest.setup.ts"],

Expect response to match OpenAPI path

import superagent from "superagent";
import openapi from "./openapi.json"; // OpenAPI 3 schema

describe("my api", () => {
  it("should have valid /fantastic response, according to spec", async () => {
    const url = `http://paspi.nrk.no/some/fantastic/path`;
    const response = await superagent.get(url).accept("application/json");
    // Asserts that:
    // - mime-type matches
    // - response code exists (or default)
    // - the schema matches the response body (assumes it is JSON)
    await expect(response).toMatchApiResponse(openapi, "get", "/fantastic");
  });
});

Expect object to match a part of a OpenAPI document

import openapi from "./openapi.json"; // OpenAPI 3 schema

describe("my complex api", () => {
  it("should match SimpleLink", async () => {
    const myLink = { href: "/my/fantastic/link" };
    // Asserts that:
    // - the reference can be resolved
    // - the resolved schema matches expected value
    await expect(myLink).toMatchRef$(
      openapi,
      "#/components/schemas/SimpleLink"
    );
  });
});

FAQs

Package last updated on 10 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc