Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/readmeio/jest-expect-openapi

Jest/Vitest matcher for asserting valid OpenAPI definitions
https://github.com/readmeio/jest-expect-openapi

jest oas openapi vitest

Last synced: 6 days ago
JSON representation

Jest/Vitest matcher for asserting valid OpenAPI definitions

Awesome Lists containing this project

README

        

# jest-expect-openapi

A [Jest](https://jestjs.io/) custom matcher for asserting valid [OpenAPI](https://en.wikipedia.org/wiki/OpenAPI_Specification) definitions. Also supports [Vitest](https://vitest.dev/).

[![npm](https://img.shields.io/npm/v/jest-expect-openapi)](https://npm.im/jest-expect-openapi) [![Build](https://github.com/readmeio/jest-expect-openapi/workflows/CI/badge.svg)](https://github.com/readmeio/jest-expect-openapi)



ReadMe Open Source

## Installation

```sh
npm install jest-expect-openapi --save-dev
```

## Usage

```js
import toBeAValidOpenAPIDefinition from 'jest-expect-openapi';

expect.extend({ toBeAValidOpenAPIDefinition });

test('should be a valid OpenAPI definition', () => {
expect(oas).toBeAValidOpenAPIDefinition();
});

test('should not be a valid OpenAPI definition', () => {
expect(invalidOas).not.toBeAValidOpenAPIDefinition();
});
```

The usage is nearly identical in Vitest:

```js
import toBeAValidOpenAPIDefinition from 'jest-expect-openapi';
import { expect, test } from 'vitest';

expect.extend({ toBeAValidOpenAPIDefinition });

test('should be a valid OpenAPI definition', () => {
expect(oas).toBeAValidOpenAPIDefinition();
});

test('should not be a valid OpenAPI definition', () => {
expect(invalidOas).not.toBeAValidOpenAPIDefinition();
});
```