-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): resolve nested custom object (#167)
- Loading branch information
1 parent
d3225fb
commit 8886a73
Showing
3 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
packages/devtools-kit/src/core/component/state/__tests__/format.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as format from '../format' | ||
import { INFINITY, NAN, NEGATIVE_INFINITY, UNDEFINED } from '../constants' | ||
|
||
describe('format: displayText and rawValue can be calculated by formatInspectorStateValue, getRawValue', () => { | ||
describe('type: literals', () => { | ||
// eslint-disable-next-line test/consistent-test-it | ||
test.each([ | ||
{ literal: 'test-string', displayText: 'test-string' }, | ||
{ literal: 123, displayText: 123 }, | ||
{ literal: true, displayText: true }, | ||
{ literal: null, displayText: 'null' }, | ||
// Tokenlized values | ||
{ literal: INFINITY, displayText: 'Infinity' }, | ||
{ literal: NAN, displayText: 'NaN' }, | ||
{ literal: NEGATIVE_INFINITY, displayText: '-Infinity' }, | ||
{ literal: UNDEFINED, displayText: 'undefined' }, | ||
])('type: %s', (value) => { | ||
const displayText = format.formatInspectorStateValue(value.literal) | ||
const rawValue = format.getRawValue(value.literal).value | ||
|
||
expect(displayText).toBe(value.displayText) | ||
expect(rawValue).toBe(value.literal) | ||
}) | ||
}) | ||
|
||
it('type: plain object', () => { | ||
const value = { foo: 'bar' } | ||
const displayText = format.formatInspectorStateValue(value) | ||
const rawValue = format.getRawValue(value).value | ||
|
||
expect(displayText).toBe('Object') | ||
expect(rawValue).toEqual(value) | ||
}) | ||
|
||
it('type: array', () => { | ||
const value = ['foo', { bar: 'baz' }] | ||
const displayText = format.formatInspectorStateValue(value) | ||
const rawValue = format.getRawValue(value).value | ||
|
||
expect(displayText).toBe('Array[2]') | ||
expect(rawValue).toEqual(value) | ||
}) | ||
|
||
describe('type: custom', () => { | ||
it('type: common custom', () => { | ||
const value = { _custom: { displayText: 'custom-display', value: Symbol(123) } } | ||
const displayText = format.formatInspectorStateValue(value) | ||
const rawValue = format.getRawValue(value).value | ||
|
||
expect(displayText).toBe(value._custom.displayText) | ||
expect(rawValue).toEqual(value._custom.value) | ||
}) | ||
|
||
it('type: nested custom', () => { | ||
const value = { | ||
_custom: { | ||
displayText: 'custom-display', | ||
value: { | ||
_custom: { displayText: 'nested-custom-display', value: Symbol(123) }, | ||
}, | ||
}, | ||
} | ||
|
||
const displayText = format.formatInspectorStateValue(value) | ||
const rawValue = format.getRawValue(value).value | ||
|
||
expect(displayText).toBe(value._custom.value._custom.displayText) | ||
expect(rawValue).toEqual(value._custom.value._custom.value) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters