One common way to decorate strings is by using placeholders:
let name = "Bob";
console.log("Hello, %s.", name) // => Outputs: "Hello, Bob."
I'm curious if there's a way to access specific values within an object being passed in without specifying the key. This scenario arises during testing with Jest, particularly when looping through an array of objects:
let people = [
{
id: 1,
name: "Bob",
age: 25
},
{
id: 2,
name: "Fred",
age: 19
}
];
describe.each(people)(
`When the person is %s`,
(person) => {
it(`It should say "Hello, ${person.name}`, () => {...})
}
My goal is for the console output to display:
"When the person is Bob > It should ..."
... however, the current output is:
"When the person is {
id: 1,
name: "Bob",
age: 25
} > It should ...
Is there a method to use something like '%s.name' as a decorator before the object reference is provided, to make the test output simpler?