@nrk/expect-openapi
TypeScript icon, indicating that this package has built-in type declarations

2.6.0 • Public • Published

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"
    );
  });
});

Readme

Keywords

none

Package Sidebar

Install

npm i @nrk/expect-openapi

Weekly Downloads

104

Version

2.6.0

License

MIT

Unpacked Size

18.4 kB

Total Files

17

Last publish

Collaborators

  • stians
  • lorecaster
  • nrk-ps-teamcity
  • swla
  • nrk-midas-jenkins
  • andorpandor
  • nrkrichard
  • gesi
  • gundelsby-nrk
  • jonstalecarlsen
  • mslhm
  • nrk-sofie-ci
  • nytamin
  • jesperstarkar
  • skjalgepalg
  • eirikhalvard
  • astokke
  • n640071
  • jfjeldskaar
  • sondrbw
  • henrik-mattsson
  • olapeter
  • dervodev
  • stefanogdennrk
  • haavardm
  • yr
  • nrk-kurator-jenkins
  • torgeilo
  • nrk-user-sync
  • dhdeploy
  • espenwa
  • ovstetun
  • stianlj
  • haraldkj
  • mariusu
  • cristobal
  • knuthaug
  • thohalv
  • johnarne
  • eshaswini
  • morrow
  • oyvindeh
  • laat
  • toggu
  • nrk-jenkins
  • zenangst
  • plomma
  • evjand
  • moltubakk
  • mariehovland
  • ingridguren
  • lu-lux
  • andersli
  • silje
  • stiandg
  • sjurlur
  • andipodnrk
  • pkej
  • yosrimti
  • morten.nyhaug
  • ingvildcath
  • erlend.jones
  • brneirik
  • mollerse
  • tbnrk
  • nordanke
  • simonmitternacht
  • martintorgersen
  • rebchr
  • steipal
  • carinafraning
  • discobus
  • eirikjstnrk
  • martingundersen
  • tinkajts
  • hallvardlid
  • tomivar
  • ajaco
  • tobinus
  • mortenok
  • feiring
  • nrk-ark-deploy
  • jeangilbertlouis
  • heidimork
  • ingriddraagen
  • fridajalborg
  • bruusi
  • rosvoll
  • christianeide
  • enordby
  • glen_imrie
  • mia.aasbakken
  • elathamna
  • evjjan17
  • olatoft
  • kongsrud
  • chrpeter
  • ingvildforseth
  • haraldk76
  • stigok
  • johannesodland
  • anders993
  • vildefj
  • vildepk
  • helenper
  • rolerboler
  • meloygutt
  • anders.baggethun
  • espenhalstensen
  • andreeldareide
  • ytterbo
  • vagifabilov
  • hermangudesen
  • haakemon
  • henningkoller
  • teodor-elstad
  • danjohnrk
  • opet
  • andrefau
  • madsern
  • cbjerkan
  • kariaan
  • gardkroyer
  • mikkelnygard
  • siddise
  • klizter
  • edplayz
  • trulsl
  • miatollaksvik
  • machineboycom
  • claudio-nrk
  • grimbur
  • n07073
  • theasparrowhawk
  • shieldyarmor
  • emte123
  • supermeisen
  • toshb
  • arevjensen
  • balte
  • eschoien
  • maar1052
  • ragnaroh-nrk
  • rannveignc
  • haraldsk
  • luminrk
  • eskilgh
  • torsrex
  • thormodb
  • joakimmohn
  • ebrautaset
  • kjellovenordlien
  • janerikbr
  • gunderwonder
  • julusian
  • daardal
  • mmep
  • jimalexberger
  • siivers
  • muddah
  • ihlnrk
  • morten-nrk
  • kristjgr
  • henrk
  • knutbo
  • sokkemannen
  • sanderknrk
  • jensrage
  • kjellvnnrk
  • nicklassvendsrud
  • ellenulrik
  • jorn_georg
  • bjornhels
  • ingryee
  • halvorh
  • phajsi
  • martiosk
  • tobiasrp
  • jimmeloysund
  • larsjorgentvedt
  • kjartanmichalsen
  • mariusenerlynrk
  • kennethdammyr
  • nikolai.kjarem.ellingsen