|
@@ -5,7 +5,6 @@ import mediumDateTime from './mediumDateTime' |
|
|
const isInvalidDate = (d: Date) => isNaN(d.getTime()) |
|
|
const isInvalidDate = (d: Date) => isNaN(d.getTime()) |
|
|
const invalidDateString = () => fc.string().filter(s => isInvalidDate(new Date(s))) |
|
|
const invalidDateString = () => fc.string().filter(s => isInvalidDate(new Date(s))) |
|
|
const validDateString = () => fc.string().filter(s => !isInvalidDate(new Date(s))) |
|
|
const validDateString = () => fc.string().filter(s => !isInvalidDate(new Date(s))) |
|
|
const invalidDate = () => fc.object().filter(o => !(o as unknown as Date)) |
|
|
|
|
|
|
|
|
|
|
|
it('should exist', () => { |
|
|
it('should exist', () => { |
|
|
expect(mediumDateTime).toBeDefined() |
|
|
expect(mediumDateTime).toBeDefined() |
|
@@ -20,70 +19,58 @@ it('should accept a minimum of 1 argument', () => { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('on numeric arguments', () => { |
|
|
describe('on numeric arguments', () => { |
|
|
describe('on invalid values', () => { |
|
|
|
|
|
it('should throw an error on NaN', () => { |
|
|
|
|
|
expect(() => mediumDateTime(NaN)).toThrow(RangeError) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
it('should throw an error on NaN', () => { |
|
|
|
|
|
expect(() => mediumDateTime(NaN)).toThrow(RangeError) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('on valid values', () => { |
|
|
|
|
|
it('should return a formatted string', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
fc.integer(), |
|
|
|
|
|
v => { |
|
|
|
|
|
expect(typeof mediumDateTime(v)).toBe('string') |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
it('should return a formatted string', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
fc.integer(), |
|
|
|
|
|
v => { |
|
|
|
|
|
expect(typeof mediumDateTime(v)).toBe('string') |
|
|
|
|
|
} |
|
|
) |
|
|
) |
|
|
}) |
|
|
|
|
|
|
|
|
) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('on string arguments', () => { |
|
|
describe('on string arguments', () => { |
|
|
describe('on invalid values', () => { |
|
|
|
|
|
it('should throw an error', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
invalidDateString(), |
|
|
|
|
|
v => { |
|
|
|
|
|
expect(() => mediumDateTime(v)).toThrow(RangeError) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
it('should throw an error given non-parseable values', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
invalidDateString(), |
|
|
|
|
|
v => { |
|
|
|
|
|
expect(() => mediumDateTime(v)).toThrow(RangeError) |
|
|
|
|
|
} |
|
|
) |
|
|
) |
|
|
}) |
|
|
|
|
|
|
|
|
) |
|
|
}) |
|
|
}) |
|
|
describe('on valid values', () => { |
|
|
|
|
|
it('should return a formatted string', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
validDateString(), |
|
|
|
|
|
v => { |
|
|
|
|
|
expect(typeof mediumDateTime(v)).toBe('string') |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
it('should return a string given parseable values', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
validDateString(), |
|
|
|
|
|
v => { |
|
|
|
|
|
expect(typeof mediumDateTime(v)).toBe('string') |
|
|
|
|
|
} |
|
|
) |
|
|
) |
|
|
}) |
|
|
|
|
|
|
|
|
) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('on object arguments', () => { |
|
|
describe('on object arguments', () => { |
|
|
describe('on non-datelike values', () => { |
|
|
|
|
|
it('should throw an error', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
invalidDate(), |
|
|
|
|
|
v => { |
|
|
|
|
|
expect(() => mediumDateTime(v)).toThrow(RangeError) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
it('should throw an error given non-datelike values', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
fc.object(), |
|
|
|
|
|
v => { |
|
|
|
|
|
expect(() => mediumDateTime(v)).toThrow(RangeError) |
|
|
|
|
|
} |
|
|
) |
|
|
) |
|
|
}) |
|
|
|
|
|
|
|
|
) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('on non-datelike arguments', () => { |
|
|
|
|
|
it('should throw an error', () => { |
|
|
|
|
|
|
|
|
it('should throw an error given non-datelike arguments', () => { |
|
|
fc.assert( |
|
|
fc.assert( |
|
|
fc.property( |
|
|
fc.property( |
|
|
fc.anything().filter(v => !['number', 'string', 'object'].includes(typeof v)), |
|
|
fc.anything().filter(v => !['number', 'string', 'object'].includes(typeof v)), |
|
@@ -93,4 +80,15 @@ describe('on non-datelike arguments', () => { |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it('should return a string given date values', () => { |
|
|
|
|
|
fc.assert( |
|
|
|
|
|
fc.property( |
|
|
|
|
|
fc.date(), |
|
|
|
|
|
d => { |
|
|
|
|
|
expect(typeof mediumDateTime(d)).toBe('string') |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |