diff --git a/.gitignore b/.gitignore index 787e0fc..e336964 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules dist .idea/ +coverage/ diff --git a/package.json b/package.json index 2ea858b..ad3500a 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -27,8 +27,13 @@ }, "name": "@theoryofnekomata/datetime-commons", "author": "TheoryOfNekomata ", + "repository": { + "type": "git", + "url":"https://code.modal.sh/TheoryOfNekomata/datetime-commons.git" + }, "module": "dist/datetime-commons.esm.js", "devDependencies": { + "date-fns": "^2.16.1", "fast-check": "^2.3.0", "husky": "^4.3.0", "tsdx": "^0.13.3", diff --git a/src/index.test.ts b/src/index.test.ts new file mode 100644 index 0000000..42429a4 --- /dev/null +++ b/src/index.test.ts @@ -0,0 +1,7 @@ +import * as index from './index' + +describe('mediumDateTime', () => { + it('should exist', () => { + expect(index.mediumDateTime).toBeDefined() + }) +}) diff --git a/src/mediumDateTime.test.ts b/src/mediumDateTime.test.ts index 77ba0f3..d13fc3c 100644 --- a/src/mediumDateTime.test.ts +++ b/src/mediumDateTime.test.ts @@ -5,7 +5,6 @@ import mediumDateTime from './mediumDateTime' const isInvalidDate = (d: Date) => isNaN(d.getTime()) const invalidDateString = () => 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', () => { expect(mediumDateTime).toBeDefined() @@ -20,70 +19,58 @@ it('should accept a minimum of 1 argument', () => { }) 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 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 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.property( 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') + } + ) + ) + }) }) diff --git a/tsconfig.json b/tsconfig.json index 816d092..564494b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,8 +11,11 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, + "noImplicitAny": true, "noFallthroughCasesInSwitch": true, + "allowSyntheticDefaultImports": true, "moduleResolution": "node", + "baseUrl": "./", "jsx": "react", "esModuleInterop": true }