diff --git a/.eslintrc b/.eslintrc index 97e8a644..afe54d03 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,6 +19,7 @@ "@typescript-eslint/interface-name-prefix": 0, "@typescript-eslint/no-explicit-any": 0, "@typescript-eslint/no-unused-vars": 0, + "import/no-extraneous-dependencies": ["error", {"devDependencies": ["setupTests.ts", "**/*spec.tsx"]}], "import/no-unresolved": 0, "prettier/prettier": ["error", { "singleQuote": true }], "react/destructuring-assignment": 0, diff --git a/__test_utils__/TestInput.js b/__test_utils__/TestInput.tsx similarity index 100% rename from __test_utils__/TestInput.js rename to __test_utils__/TestInput.tsx diff --git a/__test_utils__/TestInputHoc.js b/__test_utils__/TestInputHoc.tsx similarity index 100% rename from __test_utils__/TestInputHoc.js rename to __test_utils__/TestInputHoc.tsx diff --git a/__test_utils__/immediate.js b/__test_utils__/immediate.ts similarity index 100% rename from __test_utils__/immediate.js rename to __test_utils__/immediate.ts diff --git a/__tests__/Element-spec.js b/__tests__/Element-spec.tsx similarity index 98% rename from __tests__/Element-spec.js rename to __tests__/Element-spec.tsx index b20938cd..f6d316f4 100644 --- a/__tests__/Element-spec.js +++ b/__tests__/Element-spec.tsx @@ -2,7 +2,7 @@ import React from 'react'; import sinon from 'sinon'; import { mount } from 'enzyme'; -import Formsy, { withFormsy } from './..'; +import Formsy, { withFormsy } from '..'; import immediate from '../__test_utils__/immediate'; import TestInput, { InputFactory } from '../__test_utils__/TestInput'; @@ -49,7 +49,7 @@ describe('Element', () => { it('should set back to pristine value when running reset', () => { let reset = null; const Input = InputFactory({ - componentDidMount: function() { + componentDidMount() { reset = this.props.resetValue; }, }); @@ -68,7 +68,7 @@ describe('Element', () => { it('should return error message passed when calling getErrorMessage()', () => { let errorMessage = null; const Input = InputFactory({ - componentDidMount: function() { + componentDidMount() { errorMessage = this.props.errorMessage; }, }); @@ -103,7 +103,7 @@ describe('Element', () => { it('should return true or false when calling isRequired() depending on passed required attribute', () => { const isRequireds = []; const Input = InputFactory({ - componentDidMount: function() { + componentDidMount() { isRequireds.push(this.props.isRequired); }, }); @@ -123,7 +123,7 @@ describe('Element', () => { it('should return true or false when calling showRequired() depending on input being empty and required is passed, or not', () => { const showRequireds = []; const Input = InputFactory({ - componentDidMount: function() { + componentDidMount() { showRequireds.push(this.props.showRequired); }, }); diff --git a/__tests__/Formsy-spec.js b/__tests__/Formsy-spec.tsx similarity index 100% rename from __tests__/Formsy-spec.js rename to __tests__/Formsy-spec.tsx diff --git a/__tests__/Rules-equals-spec.js b/__tests__/Rules-equals-spec.tsx similarity index 100% rename from __tests__/Rules-equals-spec.js rename to __tests__/Rules-equals-spec.tsx diff --git a/__tests__/Rules-isAlpha-spec.js b/__tests__/Rules-isAlpha-spec.tsx similarity index 100% rename from __tests__/Rules-isAlpha-spec.js rename to __tests__/Rules-isAlpha-spec.tsx diff --git a/__tests__/Rules-isAlphanumeric-spec.js b/__tests__/Rules-isAlphanumeric-spec.tsx similarity index 100% rename from __tests__/Rules-isAlphanumeric-spec.js rename to __tests__/Rules-isAlphanumeric-spec.tsx diff --git a/__tests__/Rules-isEmail-spec.js b/__tests__/Rules-isEmail-spec.tsx similarity index 100% rename from __tests__/Rules-isEmail-spec.js rename to __tests__/Rules-isEmail-spec.tsx diff --git a/__tests__/Rules-isEmptyString-spec.js b/__tests__/Rules-isEmptyString-spec.tsx similarity index 98% rename from __tests__/Rules-isEmptyString-spec.js rename to __tests__/Rules-isEmptyString-spec.tsx index c689c9cf..cb874b2f 100644 --- a/__tests__/Rules-isEmptyString-spec.js +++ b/__tests__/Rules-isEmptyString-spec.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import Formsy from './..'; +import Formsy from '..'; import { InputFactory } from '../__test_utils__/TestInput'; const TestInput = InputFactory({ diff --git a/__tests__/Rules-isExisty-spec.js b/__tests__/Rules-isExisty-spec.tsx similarity index 100% rename from __tests__/Rules-isExisty-spec.js rename to __tests__/Rules-isExisty-spec.tsx diff --git a/__tests__/Rules-isFloat-spec.js b/__tests__/Rules-isFloat-spec.tsx similarity index 100% rename from __tests__/Rules-isFloat-spec.js rename to __tests__/Rules-isFloat-spec.tsx diff --git a/__tests__/Rules-isInt-spec.js b/__tests__/Rules-isInt-spec.tsx similarity index 100% rename from __tests__/Rules-isInt-spec.js rename to __tests__/Rules-isInt-spec.tsx diff --git a/__tests__/Rules-isLength-spec.js b/__tests__/Rules-isLength-spec.tsx similarity index 100% rename from __tests__/Rules-isLength-spec.js rename to __tests__/Rules-isLength-spec.tsx diff --git a/__tests__/Rules-isNumeric-spec.js b/__tests__/Rules-isNumeric-spec.tsx similarity index 100% rename from __tests__/Rules-isNumeric-spec.js rename to __tests__/Rules-isNumeric-spec.tsx diff --git a/__tests__/Rules-isUrl-spec.js b/__tests__/Rules-isUrl-spec.tsx similarity index 100% rename from __tests__/Rules-isUrl-spec.js rename to __tests__/Rules-isUrl-spec.tsx diff --git a/__tests__/Rules-isWords-spec.js b/__tests__/Rules-isWords-spec.tsx similarity index 100% rename from __tests__/Rules-isWords-spec.js rename to __tests__/Rules-isWords-spec.tsx diff --git a/__tests__/Rules-maxLength-spec.js b/__tests__/Rules-maxLength-spec.tsx similarity index 100% rename from __tests__/Rules-maxLength-spec.js rename to __tests__/Rules-maxLength-spec.tsx diff --git a/__tests__/Rules-minLength-spec.js b/__tests__/Rules-minLength-spec.tsx similarity index 100% rename from __tests__/Rules-minLength-spec.js rename to __tests__/Rules-minLength-spec.tsx diff --git a/__tests__/Utils-spec.js b/__tests__/Utils-spec.tsx similarity index 100% rename from __tests__/Utils-spec.js rename to __tests__/Utils-spec.tsx diff --git a/__tests__/Validation-spec.js b/__tests__/Validation-spec.tsx similarity index 99% rename from __tests__/Validation-spec.js rename to __tests__/Validation-spec.tsx index 2c21e261..287c6160 100644 --- a/__tests__/Validation-spec.js +++ b/__tests__/Validation-spec.tsx @@ -127,7 +127,7 @@ describe('Validation', () => { it('should be able to use provided validate function', () => { let isValid = false; const CustomInput = InputFactory({ - componentDidMount: function() { + componentDidMount() { isValid = this.props.isValid; }, }); diff --git a/package.json b/package.json index d34d4ffa..ca5bb0c1 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "^.+\\.(js|jsx|ts|tsx)$": "babel-jest" }, "setupFilesAfterEnv": [ - "./setupTests.js" + "./setupTests.ts" ] }, "license": "MIT", @@ -50,7 +50,7 @@ "build:types": "tsc --emitDeclarationOnly", "changelog": "auto-changelog", "deploy": "np", - "format": "prettier --write \"**/*.{js,ts}\"", + "format": "prettier --write \"**/*.{js,jsx,ts,tsx}\"", "lint": "eslint src/**/*", "preversion": "npm run lint", "test": "jest", @@ -68,6 +68,9 @@ "@babel/preset-env": "^7.4.5", "@babel/preset-react": "^7.0.0", "@babel/preset-typescript": "^7.3.3", + "@types/enzyme": "^3.9.4", + "@types/jasmine": "^3.3.13", + "@types/jest": "^24.0.15", "@types/prop-types": "^15.7.1", "@types/react": "^16.8.22", "@types/react-dom": "^16.8.4", diff --git a/setupTests.js b/setupTests.ts similarity index 100% rename from setupTests.js rename to setupTests.ts diff --git a/tsconfig.json b/tsconfig.json index 347b6523..e889b43f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "declaration": true, "esModuleInterop": true, + "jsx": "react", "lib": ["dom", "es5", "es6", "es7", "es2017.object"], "outDir": "dist", "sourceMap": true diff --git a/yarn.lock b/yarn.lock index c808405d..5f687ebb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1003,6 +1003,21 @@ dependencies: "@babel/types" "^7.3.0" +"@types/cheerio@*": + version "0.22.11" + resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.11.tgz#61c0facf9636d14ba5f77fc65ed8913aa845d717" + integrity sha512-x0X3kPbholdJZng9wDMhb2swvUi3UYRNAuWAmIPIWlfgAJZp//cql/qblE7181Mg7SjWVwq6ldCPCLn5AY/e7w== + dependencies: + "@types/node" "*" + +"@types/enzyme@^3.9.4": + version "3.9.4" + resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.9.4.tgz#08f3ebfa24aa881021693a0fe615d6d2720c07ad" + integrity sha512-bQcwt5gcKnekrbci4hcapfE2J6rkkFbHM1l4VobLtSl4ogOfj0lvSxrdS6FftCakmJqqPBqdQCwb5KnlivL6SQ== + dependencies: + "@types/cheerio" "*" + "@types/react" "*" + "@types/eslint-visitor-keys@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" @@ -1047,6 +1062,23 @@ "@types/istanbul-lib-coverage" "*" "@types/istanbul-lib-report" "*" +"@types/jasmine@^3.3.13": + version "3.3.13" + resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-3.3.13.tgz#d5daabb0af47bcddee40597acf6e804433bab439" + integrity sha512-iczmLoIiVymaD1TIr2UctxjFkNEslVE/QtNAUmpDsD71cZfZBAsPCUv1Y+8AwsfA8bLx2ccr7d95T9w/UAirlQ== + +"@types/jest-diff@*": + version "20.0.1" + resolved "https://registry.yarnpkg.com/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89" + integrity sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA== + +"@types/jest@^24.0.15": + version "24.0.15" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.15.tgz#6c42d5af7fe3b44ffff7cc65de7bf741e8fa427f" + integrity sha512-MU1HIvWUme74stAoc3mgAi+aMlgKOudgEvQDIm1v4RkrDudBh1T+NFp5sftpBAdXdx1J0PbdpJ+M2EsSOi1djA== + dependencies: + "@types/jest-diff" "*" + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"