diff --git a/package-lock.json b/package-lock.json index 38dca00..2ab45c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,8 @@ }, "devDependencies": { "@types/mocha": "^10.0.1", + "@types/react": "^18.0.33", + "@types/react-dom": "^18.0.11", "coveralls": "^3.1.0", "eslint": "^8.1", "mocha": "^10.0", @@ -750,6 +752,38 @@ "dev": true, "peer": true }, + "node_modules/@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", + "dev": true + }, + "node_modules/@types/react": { + "version": "18.0.33", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.33.tgz", + "integrity": "sha512-sHxzVxeanvQyQ1lr8NSHaj0kDzcNiGpILEVt69g9S31/7PfMvNCKLKcsHw4lYKjs3cGNJjXSP4mYzX43QlnjNA==", + "dev": true, + "dependencies": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "node_modules/@types/react-dom": { + "version": "18.0.11", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.11.tgz", + "integrity": "sha512-O38bPbI2CWtgw/OoQoY+BRelw7uysmXbWvw3nLWO21H1HSh+GOlqPuXshJfjmpNlKiiSDG9cc1JZAaMmVdcTlw==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/scheduler": { + "version": "0.16.3", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.3.tgz", + "integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==", + "dev": true + }, "node_modules/acorn": { "version": "8.8.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", @@ -1234,6 +1268,12 @@ "node": ">= 8" } }, + "node_modules/csstype": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.2.tgz", + "integrity": "sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==", + "dev": true + }, "node_modules/dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", diff --git a/package.json b/package.json index eb32da6..bc31b02 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,8 @@ }, "devDependencies": { "@types/mocha": "^10.0.1", + "@types/react": "^18.0.33", + "@types/react-dom": "^18.0.11", "coveralls": "^3.1.0", "eslint": "^8.1", "mocha": "^10.0", diff --git a/test/html-to-react-tests.ts b/test/html-to-react-tests.ts index 65873ca..b30b947 100644 --- a/test/html-to-react-tests.ts +++ b/test/html-to-react-tests.ts @@ -7,7 +7,7 @@ import {ProcessNodeDefinitions} from '..'; import {booleanAttrs} from './boolattrs'; describe('Html2React', () => { - const parser = new Parser(); + const parser = Parser(); describe('parse valid HTML', () => { it('should return a valid HTML string', () => { @@ -185,10 +185,10 @@ describe('Html2React', () => { const reactComponent = parser.parse(htmlInput); - const children = reactComponent.props.children.flat().filter((c) => { + const children = reactComponent.props.children.flat().filter((c: any) => { return c.hasOwnProperty('key'); }); - const keys = children.map((child) => { + const keys = children.map((child: any) => { return child.key; }); deepStrictEqual(keys, ['0', '1', ]); @@ -327,8 +327,8 @@ describe('Html2React', () => { }); describe('with custom processing instructions', () => { - const parser = new Parser(); - const processNodeDefinitions = new ProcessNodeDefinitions(); + const parser = Parser(); + const processNodeDefinitions = ProcessNodeDefinitions(); describe('parse valid HTML', () => { it('should return nothing with only a single
element', () => { @@ -337,7 +337,7 @@ describe('Html2React', () => { return true; }; const processingInstructions = [{ - shouldProcessNode: function (node) { + shouldProcessNode: (node: any) => { return node.name && node.name !== 'p'; }, processNode: processNodeDefinitions.processDefaultNode, @@ -359,7 +359,7 @@ describe('Html2React', () => { }; const processingInstructions = [{ - shouldProcessNode: function (node) { + shouldProcessNode: (node: any) => { return node.type === 'text' || node.name !== 'p'; }, processNode: processNodeDefinitions.processDefaultNode, @@ -381,16 +381,16 @@ describe('Html2React', () => { const processingInstructions = [ { replaceChildren: true, - shouldProcessNode: function (node) { + shouldProcessNode: (node: any) => { return (node.attribs || {})['data-test'] === 'foo'; }, - processNode: function (node, children, index) { + processNode: (node: any, children: any, index: number) => { return React.createElement('h1', {key: index,}, 'Heading'); }, }, { // Anything else - shouldProcessNode: function (node) { + shouldProcessNode: (node: any) => { return true; }, processNode: processNodeDefinitions.processDefaultNode, @@ -416,16 +416,16 @@ describe('Html2React', () => { const processingInstructions = [ { // Custom