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

https://github.com/roberto/chakram-joi

Chakram assertion for Joi schema.
https://github.com/roberto/chakram-joi

Last synced: 12 months ago
JSON representation

Chakram assertion for Joi schema.

Awesome Lists containing this project

README

          

# Chakram-Joi

[Chakram](https://github.com/dareid/chakram) assertion for checking responses using [Joi](https://github.com/hapijs/joi) schema.

## Installation

```
npm install --save-dev chakram-joi
```

## Setup

```js
chakram.addMethod('joi', require('chakram-joi'));
```

## Basic Usage

```js
const schema = joi.object().keys({
name: joi.string()
});

expect(response).to.joi(schema);
```

## Custom Options

Joi has several [options for validation](https://github.com/hapijs/joi/blob/v9.0.0/API.md#validatevalue-schema-options-callback) and it's possible to use them as shown bellow:

```js
expect(response).to.joi(schema, { abortEarly: false });
```

Default options:

```yml
abortEarly: true # stops validation on the first error
presence: 'required' # declared items must be found
allowUnknown: true # unknown object keys are ignored
```

## License

MIT