|
| 1 | +import * as format from '../format' |
| 2 | +import { INFINITY, NAN, NEGATIVE_INFINITY, UNDEFINED } from '../constants' |
| 3 | + |
| 4 | +describe('format: displayText and rawValue can be calculated by formatInspectorStateValue, getRawValue', () => { |
| 5 | + describe('type: literals', () => { |
| 6 | + // eslint-disable-next-line test/consistent-test-it |
| 7 | + test.each([ |
| 8 | + { literal: 'test-string', displayText: 'test-string' }, |
| 9 | + { literal: 123, displayText: 123 }, |
| 10 | + { literal: true, displayText: true }, |
| 11 | + { literal: null, displayText: 'null' }, |
| 12 | + // Tokenlized values |
| 13 | + { literal: INFINITY, displayText: 'Infinity' }, |
| 14 | + { literal: NAN, displayText: 'NaN' }, |
| 15 | + { literal: NEGATIVE_INFINITY, displayText: '-Infinity' }, |
| 16 | + { literal: UNDEFINED, displayText: 'undefined' }, |
| 17 | + ])('type: %s', (value) => { |
| 18 | + const displayText = format.formatInspectorStateValue(value.literal) |
| 19 | + const rawValue = format.getRawValue(value.literal).value |
| 20 | + |
| 21 | + expect(displayText).toBe(value.displayText) |
| 22 | + expect(rawValue).toBe(value.literal) |
| 23 | + }) |
| 24 | + }) |
| 25 | + |
| 26 | + it('type: plain object', () => { |
| 27 | + const value = { foo: 'bar' } |
| 28 | + const displayText = format.formatInspectorStateValue(value) |
| 29 | + const rawValue = format.getRawValue(value).value |
| 30 | + |
| 31 | + expect(displayText).toBe('Object') |
| 32 | + expect(rawValue).toEqual(value) |
| 33 | + }) |
| 34 | + |
| 35 | + it('type: array', () => { |
| 36 | + const value = ['foo', { bar: 'baz' }] |
| 37 | + const displayText = format.formatInspectorStateValue(value) |
| 38 | + const rawValue = format.getRawValue(value).value |
| 39 | + |
| 40 | + expect(displayText).toBe('Array[2]') |
| 41 | + expect(rawValue).toEqual(value) |
| 42 | + }) |
| 43 | + |
| 44 | + describe('type: custom', () => { |
| 45 | + it('type: common custom', () => { |
| 46 | + const value = { _custom: { displayText: 'custom-display', value: Symbol(123) } } |
| 47 | + const displayText = format.formatInspectorStateValue(value) |
| 48 | + const rawValue = format.getRawValue(value).value |
| 49 | + |
| 50 | + expect(displayText).toBe(value._custom.displayText) |
| 51 | + expect(rawValue).toEqual(value._custom.value) |
| 52 | + }) |
| 53 | + |
| 54 | + it('type: nested custom', () => { |
| 55 | + const value = { |
| 56 | + _custom: { |
| 57 | + displayText: 'custom-display', |
| 58 | + value: { |
| 59 | + _custom: { displayText: 'nested-custom-display', value: Symbol(123) }, |
| 60 | + }, |
| 61 | + }, |
| 62 | + } |
| 63 | + |
| 64 | + const displayText = format.formatInspectorStateValue(value) |
| 65 | + const rawValue = format.getRawValue(value).value |
| 66 | + |
| 67 | + expect(displayText).toBe(value._custom.value._custom.displayText) |
| 68 | + expect(rawValue).toEqual(value._custom.value._custom.value) |
| 69 | + }) |
| 70 | + }) |
| 71 | +}) |
0 commit comments