Skip to content

Commit c7cded8

Browse files
committed
Add proper rendering of objects & arrays
1 parent dd5d207 commit c7cded8

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/utils.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,31 @@ describe('utils', () => {
196196
' Some Label: %cTest Value',
197197
)
198198
})
199+
200+
it('returns message with object', () => {
201+
expect(getMessage({ a: 'Test', b: 'Value' }, 'Some Label')).toEqual(
202+
' Some Label: {"a":"Test","b":"Value"}',
203+
)
204+
})
205+
206+
it('returns message with array', () => {
207+
expect(getMessage(['Test', 'Value'], 'Some Label')).toEqual(
208+
' Some Label: ["Test","Value"]',
209+
)
210+
})
211+
212+
it('returns message with array of objects', () => {
213+
expect(
214+
getMessage(
215+
[
216+
{ a: 'Test', b: 'Value' },
217+
{ c: 'Test', d: 'Value' },
218+
],
219+
'Some Label',
220+
),
221+
).toEqual(
222+
' Some Label: [{"a":"Test","b":"Value"},{"c":"Test","d":"Value"}]',
223+
)
224+
})
199225
})
200226
})

src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ export function getMessage<T>(
3434
? `${label.padStart(DEFAULT_LABEL_SIZE, ' ')}: `
3535
: ''.padStart(DEFAULT_LABEL_SIZE + 2, ' ')
3636

37-
return `${printLabel}${stylePlaceholder(withCss)}${String(value)}`
37+
const printValue =
38+
typeof value === 'object' && value !== null
39+
? JSON.stringify(value)
40+
: String(value)
41+
42+
return `${printLabel}${stylePlaceholder(withCss)}${printValue}`
3843
}
3944

4045
export function getGroupLabel(

0 commit comments

Comments
 (0)