Skip to content

Logging of js Object with Class properties outputs empty object #5429

@dbonchev42

Description

@dbonchev42

Brief summary

Let's say we have Class1 and Class2.
If you try to console.log({ Class1, Class2 }) the output in the console will be {}.
The bug is observed only when the property is js class.

k6 version

1.4.0 - commit/a9f9e3b28a, go1.25.4

OS

Ubuntu 20.04.6

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Run the script below and check the console.error()

const DummyOne = class DummyOne {
  get() {
    return 'DummyOne';
  }
};
const DummyTwo = class DummyTwo {
  get() {
    return 'DummyTwo';
  }
};
const string = 'str';
const int = 4;

console.log(string);
console.log(int);
console.log('str + int obj ->\n', { string, int });

console.log('---------');

console.log(DummyOne);
console.log(DummyTwo);
const classesObj = { DummyOne, DummyTwo };
console.error('FAIL: classes obj ->\n', classesObj);
console.log('Try accessing property ->\n', classesObj.DummyOne.name);

Object.values(classesObj).forEach((val) => {
  console.log('foreach logging ->\n', val.name);
});

export default function () {
}

Expected behaviour

Line 23: console.error('FAIL: classes obj ->\n', classesObj); prints { DummyOne: [object Function], DummyTwo: [object Function]}

Actual behaviour

Line 23: console.error('FAIL: classes obj ->\n', classesObj); prints {}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions