File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
projects/angular2-jsonapi/src/converters/date Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { DateConverter } from './date.converter' ;
2
+ import { parseISO } from 'date-fns' ;
3
+
4
+ describe ( 'Date converter' , ( ) => {
5
+ const converter : DateConverter = new DateConverter ( ) ;
6
+
7
+ describe ( 'mask method' , ( ) => {
8
+
9
+ it ( 'Null stays null' , ( ) => {
10
+ const value = converter . mask ( null ) ;
11
+ expect ( value ) . toBeNull ( ) ;
12
+ } ) ;
13
+
14
+ it ( 'string is transformed to Date object' , ( ) => {
15
+ const value = converter . mask ( '2019-11-11' ) ;
16
+ expect ( value instanceof Date ) . toBeTruthy ( ) ;
17
+ } ) ;
18
+
19
+ it ( 'empty string is transformed to Date object' , ( ) => {
20
+ const value = converter . mask ( '' ) ;
21
+ expect ( value instanceof Date ) . toBeTruthy ( ) ;
22
+ } ) ;
23
+ } ) ;
24
+
25
+ describe ( 'unmask method' , ( ) => {
26
+
27
+ it ( 'Null stays null' , ( ) => {
28
+ const value = converter . unmask ( null ) ;
29
+ expect ( value ) . toBeNull ( ) ;
30
+ } ) ;
31
+
32
+ it ( 'Date to be transformed to string' , ( ) => {
33
+ const value = converter . unmask ( parseISO ( '2019-11-11' ) ) ;
34
+ expect ( typeof value === 'string' ) . toBeTruthy ( ) ;
35
+ } ) ;
36
+ } ) ;
37
+
38
+ } ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ export class DateConverter implements PropertyConverter {
11
11
}
12
12
13
13
unmask ( value : any ) {
14
+ if ( value === null ) {
15
+ return null ;
16
+ }
14
17
return value . toISOString ( ) ;
15
18
}
16
19
}
You can’t perform that action at this time.
0 commit comments