Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/bruno-js/src/runtime/assert-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ chai.use(function (chai, utils) {
// Objects created inside Node's vm.createContext() have a different Object constructor,
// so obj.constructor === Object fails for objects passed via res.setBody() from scripts.
// Note: toString check is more permissive than constructor check — custom class instances
const isJson = typeof obj === 'object' && obj !== null && !Array.isArray(obj)
&& Object.prototype.toString.call(obj) === '[object Object]';
const isJson = typeof obj === 'object' && obj !== null
&& (Array.isArray(obj) || Object.prototype.toString.call(obj) === '[object Object]');

this.assert(isJson, `expected ${utils.inspect(obj)} to be JSON`, `expected ${utils.inspect(obj)} not to be JSON`);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/bruno-js/src/sandbox/quickjs/shims/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const addBruShimToContext = (vm, __brunoTestResults) => {
Object.defineProperty(proto, 'json', {
get: function () {
var obj = this._obj;
var isJson = typeof obj === 'object' && obj !== null && !Array.isArray(obj) &&
Object.prototype.toString.call(obj) === '[object Object]';
var isJson = typeof obj === 'object' && obj !== null &&
(Array.isArray(obj) || Object.prototype.toString.call(obj) === '[object Object]');
this.assert(isJson, 'expected #{this} to be JSON', 'expected #{this} not to be JSON');
return this;
},
Expand Down
28 changes: 26 additions & 2 deletions packages/bruno-js/tests/runtime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,36 @@ describe('runtime', () => {
expect(results[0].status).toBe('pass');
});

it('should fail for an array', () => {
it('should pass for an array', () => {
const results = runAssertions(
[{ name: 'res.body', value: 'isJson', enabled: true }],
makeResponse([1, 2, 3])
);
expect(results[0].status).toBe('fail');
expect(results[0].status).toBe('pass');
});

it('should pass for an array of strings', () => {
const results = runAssertions(
[{ name: 'res.body', value: 'isJson', enabled: true }],
makeResponse(['A55001213ZX0A'])
);
expect(results[0].status).toBe('pass');
});

it('should pass for an empty array', () => {
const results = runAssertions(
[{ name: 'res.body', value: 'isJson', enabled: true }],
makeResponse([])
);
expect(results[0].status).toBe('pass');
});

it('should pass for an array of objects', () => {
const results = runAssertions(
[{ name: 'res.body', value: 'isJson', enabled: true }],
makeResponse([{ id: 1 }, { id: 2 }])
);
expect(results[0].status).toBe('pass');
});

it('should fail for a string', () => {
Expand Down
Loading