1
1
import * as format from '../format'
2
+ import { customTypeEnums } from '../../types'
2
3
import { INFINITY , NAN , NEGATIVE_INFINITY , UNDEFINED } from '../constants'
3
4
4
- describe ( 'format: displayText and rawValue can be calculated by formatInspectorStateValue, getRawValue ' , ( ) => {
5
+ describe ( 'format: displayText and rawValue can be calculated by formatInspectorStateValue, getRaw ' , ( ) => {
5
6
describe ( 'type: literals' , ( ) => {
6
7
// eslint-disable-next-line test/consistent-test-it
7
8
test . each ( [
@@ -16,7 +17,7 @@ describe('format: displayText and rawValue can be calculated by formatInspectorS
16
17
{ literal : UNDEFINED , displayText : 'undefined' } ,
17
18
] ) ( 'type: %s' , ( value ) => {
18
19
const displayText = format . formatInspectorStateValue ( value . literal )
19
- const rawValue = format . getRawValue ( value . literal ) . value
20
+ const rawValue = format . getRaw ( value . literal ) . value
20
21
21
22
expect ( displayText ) . toBe ( value . displayText )
22
23
expect ( rawValue ) . toBe ( value . literal )
@@ -26,7 +27,7 @@ describe('format: displayText and rawValue can be calculated by formatInspectorS
26
27
it ( 'type: plain object' , ( ) => {
27
28
const value = { foo : 'bar' }
28
29
const displayText = format . formatInspectorStateValue ( value )
29
- const rawValue = format . getRawValue ( value ) . value
30
+ const rawValue = format . getRaw ( value ) . value
30
31
31
32
expect ( displayText ) . toBe ( 'Object' )
32
33
expect ( rawValue ) . toEqual ( value )
@@ -35,7 +36,7 @@ describe('format: displayText and rawValue can be calculated by formatInspectorS
35
36
it ( 'type: array' , ( ) => {
36
37
const value = [ 'foo' , { bar : 'baz' } ]
37
38
const displayText = format . formatInspectorStateValue ( value )
38
- const rawValue = format . getRawValue ( value ) . value
39
+ const rawValue = format . getRaw ( value ) . value
39
40
40
41
expect ( displayText ) . toBe ( 'Array[2]' )
41
42
expect ( rawValue ) . toEqual ( value )
@@ -45,7 +46,7 @@ describe('format: displayText and rawValue can be calculated by formatInspectorS
45
46
it ( 'type: common custom' , ( ) => {
46
47
const value = { _custom : { displayText : 'custom-display' , value : Symbol ( 123 ) } }
47
48
const displayText = format . formatInspectorStateValue ( value )
48
- const rawValue = format . getRawValue ( value ) . value
49
+ const rawValue = format . getRaw ( value ) . value
49
50
50
51
expect ( displayText ) . toBe ( value . _custom . displayText )
51
52
expect ( rawValue ) . toEqual ( value . _custom . value )
@@ -62,7 +63,7 @@ describe('format: displayText and rawValue can be calculated by formatInspectorS
62
63
}
63
64
64
65
const displayText = format . formatInspectorStateValue ( value )
65
- const rawValue = format . getRawValue ( value ) . value
66
+ const rawValue = format . getRaw ( value ) . value
66
67
67
68
expect ( displayText ) . toBe ( value . _custom . value . _custom . displayText )
68
69
expect ( rawValue ) . toEqual ( value . _custom . value . _custom . value )
@@ -87,8 +88,9 @@ describe('format: toEdit', () => {
87
88
{ value : { foo : NAN } , target : '{"foo":NaN}' } ,
88
89
{ value : { foo : NEGATIVE_INFINITY } , target : '{"foo":-Infinity}' } ,
89
90
{ value : { foo : UNDEFINED } , target : '{"foo":undefined}' } ,
91
+ { value : '123' , customType : 'bigint' as customTypeEnums , target : '123' } ,
90
92
] ) ( 'value: $value will be deserialized to target' , ( value ) => {
91
- const deserialized = format . toEdit ( value . value )
93
+ const deserialized = format . toEdit ( value . value , value . customType )
92
94
expect ( deserialized ) . toBe ( value . target )
93
95
} )
94
96
} )
@@ -113,8 +115,9 @@ describe('format: toSubmit', () => {
113
115
{ value : '{"foo":undefined}' , target : { } } ,
114
116
// Regex test: The token in key field kept untouched.
115
117
{ value : '{"undefined": NaN }' , target : { undefined : Number . NaN } } ,
118
+ { value : '123' , customType : 'bigint' as customTypeEnums , target : BigInt ( 123 ) } ,
116
119
] ) ( 'value: $value will be serialized to target' , ( value ) => {
117
- const serialized = format . toSubmit ( value . value )
120
+ const serialized = format . toSubmit ( value . value , value . customType )
118
121
expect ( serialized ) . toStrictEqual ( value . target )
119
122
} )
120
123
} )
0 commit comments