Merge pull request #135 from dcoomber/bugfix/132-isjson-assertion

Resolve issue with to.be.json assertions Re #132
This commit is contained in:
Anoop M D 2023-03-23 14:11:55 +05:30 committed by GitHub
commit fbc6e7bff5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,19 @@ const BrunoRequest = require('../bruno-request');
const { evaluateJsTemplateLiteral, evaluateJsExpression, createResponseParser } = require('../utils');
const { expect } = chai;
chai.use(function (chai, utils) {
// Custom assertion for checking if a variable is JSON
chai.Assertion.addProperty('json', function () {
const obj = this._obj;
const isJson = typeof obj === 'object' && obj !== null && !Array.isArray(obj) && obj.constructor === Object;
this.assert(
isJson,
`expected ${utils.inspect(obj)} to be JSON`,
`expected ${utils.inspect(obj)} not to be JSON`
);
});
});
/**
* Assertion operators
@ -92,7 +105,7 @@ const evaluateRhsOperand = (rhsOperand, operator, context) => {
return;
}
// gracefulle allyow both a,b as well as [a, b]
// gracefully allow both a,b as well as [a, b]
if(operator === 'in' || operator === 'notIn') {
if(rhsOperand.startsWith('[') && rhsOperand.endsWith(']')) {
rhsOperand = rhsOperand.substring(1, rhsOperand.length - 1);
@ -267,4 +280,4 @@ class AssertRuntime {
}
}
module.exports = AssertRuntime;
module.exports = AssertRuntime;