# chai-ajv-json-schema

> Chai plugin for using AJV validation in mocha tests

Latest version **1.0.0** (published 2016-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install chai-ajv-json-schema
pnpm add chai-ajv-json-schema
yarn add chai-ajv-json-schema
bun add chai-ajv-json-schema
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-05-30 |
| First published | 2016-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | David Middleton |
| Maintainers | peon374 |
| Keywords | mocha, chai, ajv |

## Links

- npm: https://www.npmjs.com/package/chai-ajv-json-schema
- Repository: https://github.com/peon374/chai-ajv-json-schema
- Homepage: https://github.com/peon374/chai-ajv-json-schema#readme
- Issues: https://github.com/peon374/chai-ajv-json-schema/issues
- npm.io page: https://npm.io/package/chai-ajv-json-schema

## Dependencies (1)

- [ajv](https://npm.io/package/ajv.md) ^4.0.6

## Recent versions

- 1.0.0 (latest) — 2016-05-30

## README

# chai-ajv-json-schema
Chai plugin to allow JSON schema to be used with expect.
This is currently a stub and is under heavy development.
All contributions are welcome.

##Usage
This plugin adds validWithSchema to the expect validation methods.
```
expect({}).to.be.validWithSchema(['schema1','schema2])
expect({}).to.be.validWithSchema('schema1')
```

##Simple Example
```
var chai = require('chai');
var expect = chai.expect;

chai.use(require('chai-ajv-json-schema'))
chai.ajv.addSchema(require('./schemas/complex.json'), "test_schema");

describe("Look we can test against a schema", function(){
  it("checks that doAllTheThings() does all the things.", function(){
    const results = doAllTheThings();
    expect(results).to.validWithSchema("test_schema");
  })
})

```

##Complicated Example
```
var meta = require('../meta.json');
var chai = require('chai');
var expect = chai.expect;

chai.use(require('chai-ajv-json-schema'))
chai.ajv = require('../myProject/customAjvValidator')

describe("Look we can test against a schema", function(){
  it("checks that doAllTheThings() does all the things.", function(){
    const schemasNames = meta.methods.doAllTheThings.resultSchemas;
    const results = doAllTheThings();
    expect(results).to.validWithSchema(schemasNames);
  })
})
```

---
_Source: https://npm.io/package/chai-ajv-json-schema · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
