@@ -5,6 +5,7 @@ const fjs = require('..')
5
5
6
6
const Ajv = require ( 'ajv' ) . default
7
7
const Validator = require ( '../lib/validator' )
8
+ const Serializer = require ( '../lib/serializer' )
8
9
9
10
function build ( opts ) {
10
11
return fjs ( {
@@ -20,33 +21,36 @@ function build (opts) {
20
21
}
21
22
22
23
test ( 'activate debug mode' , t => {
23
- t . plan ( 4 )
24
+ t . plan ( 5 )
24
25
const debugMode = build ( { debugMode : true } )
25
26
26
27
t . type ( debugMode , 'object' )
27
28
t . ok ( debugMode . ajv instanceof Ajv )
28
29
t . ok ( debugMode . validator instanceof Validator )
30
+ t . ok ( debugMode . serializer instanceof Serializer )
29
31
t . type ( debugMode . code , 'string' )
30
32
} )
31
33
32
34
test ( 'activate debug mode truthy' , t => {
33
- t . plan ( 4 )
35
+ t . plan ( 5 )
34
36
35
37
const debugMode = build ( { debugMode : 'yes' } )
36
38
37
39
t . type ( debugMode , 'object' )
38
40
t . type ( debugMode . code , 'string' )
39
41
t . ok ( debugMode . ajv instanceof Ajv )
40
42
t . ok ( debugMode . validator instanceof Validator )
43
+ t . ok ( debugMode . serializer instanceof Serializer )
41
44
} )
42
45
43
46
test ( 'to string auto-consistent' , t => {
44
- t . plan ( 5 )
47
+ t . plan ( 6 )
45
48
const debugMode = build ( { debugMode : 1 } )
46
49
47
50
t . type ( debugMode , 'object' )
48
51
t . type ( debugMode . code , 'string' )
49
52
t . ok ( debugMode . ajv instanceof Ajv )
53
+ t . ok ( debugMode . serializer instanceof Serializer )
50
54
t . ok ( debugMode . validator instanceof Validator )
51
55
52
56
const compiled = fjs . restore ( debugMode )
@@ -55,7 +59,7 @@ test('to string auto-consistent', t => {
55
59
} )
56
60
57
61
test ( 'to string auto-consistent with ajv' , t => {
58
- t . plan ( 5 )
62
+ t . plan ( 6 )
59
63
60
64
const debugMode = fjs ( {
61
65
title : 'object with multiple types field' ,
@@ -75,6 +79,7 @@ test('to string auto-consistent with ajv', t => {
75
79
t . type ( debugMode . code , 'string' )
76
80
t . ok ( debugMode . ajv instanceof Ajv )
77
81
t . ok ( debugMode . validator instanceof Validator )
82
+ t . ok ( debugMode . serializer instanceof Serializer )
78
83
79
84
const compiled = fjs . restore ( debugMode )
80
85
const tobe = JSON . stringify ( { str : 'Foo' } )
@@ -106,3 +111,11 @@ test('to string auto-consistent with ajv-formats', t => {
106
111
t . same ( compiled ( { str :
'[email protected] ' } ) , tobe )
107
112
t . throws ( ( ) => compiled ( { str : 'foo' } ) )
108
113
} )
114
+
115
+ test ( 'debug should restore the same serializer instance' , t => {
116
+ t . plan ( 1 )
117
+
118
+ const debugMode = fjs ( { type : 'integer' } , { debugMode : 1 , rounding : 'ceil' } )
119
+ const compiled = fjs . restore ( debugMode )
120
+ t . same ( compiled ( 3.95 ) , 4 )
121
+ } )
0 commit comments