Skip to content
Merged
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
27 changes: 27 additions & 0 deletions packages/query-devtools/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest'
import {
deleteNestedDataByPath,
displayValue,
getMutationStatusColor,
getQueryStatusColorByLabel,
updateNestedDataByPath,
Expand Down Expand Up @@ -800,4 +801,30 @@ describe('Utils tests', () => {
expect(getQueryStatusColorByLabel('fetching')).toBe('blue')
})
})

describe('displayValue', () => {
it('should stringify a primitive value', () => {
expect(displayValue('hello')).toBe('"hello"')
})

it('should stringify a number', () => {
expect(displayValue(42)).toBe('42')
})

it('should serialize an object using superjson and discard meta', () => {
expect(displayValue({ a: 1, b: 'two' })).toBe('{"a":1,"b":"two"}')
})

it('should return "null" for "undefined" since only the json part is used', () => {
expect(displayValue(undefined)).toBe('null')
})

it('should return a single-line string by default', () => {
expect(displayValue({ a: 1 })).toBe('{"a":1}')
})

it('should return an indented multi-line string when "beautify" is true', () => {
expect(displayValue({ a: 1 }, true)).toBe('{\n "a": 1\n}')
})
})
})
Loading