@@ -5,6 +5,7 @@ const fjs = require('..')
55
66const Ajv = require ( 'ajv' ) . default
77const Validator = require ( '../lib/validator' )
8+ const Serializer = require ( '../lib/serializer' )
89
910function build ( opts ) {
1011 return fjs ( {
@@ -20,33 +21,36 @@ function build (opts) {
2021}
2122
2223test ( 'activate debug mode' , t => {
23- t . plan ( 4 )
24+ t . plan ( 5 )
2425 const debugMode = build ( { debugMode : true } )
2526
2627 t . type ( debugMode , 'object' )
2728 t . ok ( debugMode . ajv instanceof Ajv )
2829 t . ok ( debugMode . validator instanceof Validator )
30+ t . ok ( debugMode . serializer instanceof Serializer )
2931 t . type ( debugMode . code , 'string' )
3032} )
3133
3234test ( 'activate debug mode truthy' , t => {
33- t . plan ( 4 )
35+ t . plan ( 5 )
3436
3537 const debugMode = build ( { debugMode : 'yes' } )
3638
3739 t . type ( debugMode , 'object' )
3840 t . type ( debugMode . code , 'string' )
3941 t . ok ( debugMode . ajv instanceof Ajv )
4042 t . ok ( debugMode . validator instanceof Validator )
43+ t . ok ( debugMode . serializer instanceof Serializer )
4144} )
4245
4346test ( 'to string auto-consistent' , t => {
44- t . plan ( 5 )
47+ t . plan ( 6 )
4548 const debugMode = build ( { debugMode : 1 } )
4649
4750 t . type ( debugMode , 'object' )
4851 t . type ( debugMode . code , 'string' )
4952 t . ok ( debugMode . ajv instanceof Ajv )
53+ t . ok ( debugMode . serializer instanceof Serializer )
5054 t . ok ( debugMode . validator instanceof Validator )
5155
5256 const compiled = fjs . restore ( debugMode )
@@ -55,7 +59,7 @@ test('to string auto-consistent', t => {
5559} )
5660
5761test ( 'to string auto-consistent with ajv' , t => {
58- t . plan ( 5 )
62+ t . plan ( 6 )
5963
6064 const debugMode = fjs ( {
6165 title : 'object with multiple types field' ,
@@ -75,6 +79,7 @@ test('to string auto-consistent with ajv', t => {
7579 t . type ( debugMode . code , 'string' )
7680 t . ok ( debugMode . ajv instanceof Ajv )
7781 t . ok ( debugMode . validator instanceof Validator )
82+ t . ok ( debugMode . serializer instanceof Serializer )
7883
7984 const compiled = fjs . restore ( debugMode )
8085 const tobe = JSON . stringify ( { str : 'Foo' } )
@@ -106,3 +111,11 @@ test('to string auto-consistent with ajv-formats', t => {
106111 t . same ( compiled ( { str : 'foo@bar.com' } ) , tobe )
107112 t . throws ( ( ) => compiled ( { str : 'foo' } ) )
108113} )
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