like in chakram testing expect(WallObject).to.have.schema(expectedSchema)
. Similarly which function is there in Jest? I am using jest with supertest.
Asked
Active
Viewed 3,104 times
0

Nikita S
- 139
- 2
- 11
1 Answers
1
There is nothing available in JEST to test schema directly. I have achieved this with the help of AJV. Using AJV i am comparing schema with response and then using Jest expect checking value is true or not. like
const Ajv = require('ajv');
const ajv = new Ajv({
allErrors: true,
format: 'full',
useDefaults: true,
coerceTypes: 'array',
errorDataPath: 'property',
sourceCode: false,
});
const validateParams = (params, schema) => {
const validate = ajv.compile(schema);
const isValidParams = validate(params);
return isValidParams;
};
const result = validateParams(res.body, {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'integer',
},
email: {
type: 'string',
},
}
}
});
expect(result).toBe(true);
done();

Nikita S
- 139
- 2
- 11
-
If anyone having better options to achieve this, please post your answers – Nikita S Jun 22 '17 at 05:30