diff --git a/packages/bruno-js/src/runtime/assert-runtime.js b/packages/bruno-js/src/runtime/assert-runtime.js index eca4f845..04b49df3 100644 --- a/packages/bruno-js/src/runtime/assert-runtime.js +++ b/packages/bruno-js/src/runtime/assert-runtime.js @@ -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; \ No newline at end of file +module.exports = AssertRuntime;