I have a structure as
myObject={
Items:[
{
namePizza:{}
quantity: int
}
{
namePizza:{}
quantity: int
}
]
}
If a try console.log(myObject) Karma always return LOG:{Items:[]}
I dont understand why happen it.
A normal console.log will show you the inner content of the the javascript objects
> console.log({1,2})
> Object { 1, 2 }
BUT why does calling console.log through karma behaves differently!
Digging into the karma code; Karma modifies the original console to extract the messages and add metadata to each log. So in order to have a safe logger and to be able to log everything given to them as arguments, these libraries stringify the data you pass to the logger.
Here is what is exactly happening in karma logger:
values.push(this.stringify(args[i], 3))
as you can see, they have their own implementation of the logger.
The modified logger calls stringify against the data you send.
You can check the karma logger where the "stringifying" happens here: https://github.com/karma-runner/karma/blob/master/context/karma.js#L16
Practically most test runners or logging transports (example ravenJS for sentry) do such things.
To solve this issue; wrap your object with JSON.stringify when calling console.log
Note that JSON.stringify will not work with Sets or Maps and their weak counterpart. For those you have to call .values() against them to get the logger working correctly!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With