diff --git a/packages/query-devtools/src/__tests__/utils.test.ts b/packages/query-devtools/src/__tests__/utils.test.ts index 7f67f52e2f..019063e698 100644 --- a/packages/query-devtools/src/__tests__/utils.test.ts +++ b/packages/query-devtools/src/__tests__/utils.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest' import { deleteNestedDataByPath, + displayValue, getMutationStatusColor, getQueryStatusColorByLabel, updateNestedDataByPath, @@ -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}') + }) + }) })