Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { DateConverter } from './date.converter';
import { parseISO } from 'date-fns';

describe('Date converter', () => {
const converter: DateConverter = new DateConverter();

describe('mask method', () => {

it('Null stays null', () => {
const value = converter.mask(null);
expect(value).toBeNull();
});

it ( 'string is transformed to Date object', () => {
const value = converter.mask('2019-11-11');
expect(value instanceof Date).toBeTruthy();
});

it ( 'empty string is transformed to Date object', () => {
const value = converter.mask('');
expect(value instanceof Date).toBeTruthy();
});
});

describe('unmask method', () => {

it('Null stays null', () => {
const value = converter.unmask(null);
expect(value).toBeNull();
});

it ( 'Date to be transformed to string', () => {
const value = converter.unmask(parseISO('2019-11-11'));
expect(typeof value === 'string').toBeTruthy();
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class DateConverter implements PropertyConverter {
}

unmask(value: any) {
if (value === null) {
return null;
}
return value.toISOString();
}
}