You can add it at the top of the spec, or in cypress/support/index.js
for all specs.
cypress/plugins
is for node plugins, but browser-side plugins can be imported directly into specs or support/index.js.
const chai = require('chai');
const chaiResponseValidator = require('chai-openapi-response-validator').;
chai.use(chaiResponseValidator('path/to/openapi.yml'));
Getting around the fs.read() problem for this chai plugin
From npm: chai-openapi-response-validator
Loading your OpenAPI spec (3 different ways):
- From an object:
// Load that OpenAPI object into this plugin
chai.use(chaiResponseValidator(openApiSpec));
so you can require the object before initializing the plugin
const chai = require('chai');
const chaiResponseValidator = require('chai-openapi-response-validator');
const openApiSpec = require('path/to/openapi.yml');
chai.use(chaiResponseValidator(openApiSpec));
An alternative - take a look at cy-spok to validate the API response.
The linked video shows in action with an intercept.