Repository: remarkablemark/html-react-parser
Pull request #779 (2022-12-25 19:17:26)

test(types): refactor dtslint tests
## What is the motivation for this pull request?

test(types): refactor dtslint tests

## Checklist:

- [x] [Conventional Commits](https://www.conventionalcommits.org/)
- [x] Tests
- [ ] Documentation
- [ ] Types


Patch:
diff --git a/tsconfig.json b/tsconfig.json
index 8607ec9..a0e799c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -16,11 +16,6 @@
     },
     "jsx": "react"
   },
-  "files": [
-    "index.d.ts",
-    "lib/dom-to-react.d.ts",
-    "test/types/index.tsx",
-    "test/types/lib/attributes-to-props.ts",
-    "test/types/lib/dom-to-react.tsx"
-  ]
+  "files": ["index.d.ts", "lib/dom-to-react.d.ts"],
+  "include": ["test/types/**/*.ts", "test/types/**/*.tsx"]
 }


Test patch:
diff --git a/test/types/error.tsx b/test/types/error.tsx
new file mode 100644
index 0000000..808fef3
--- /dev/null
+++ b/test/types/error.tsx
@@ -0,0 +1,4 @@
+import parse from 'html-react-parser';
+
+// $ExpectError
+parse();
diff --git a/test/types/exports.tsx b/test/types/exports.tsx
new file mode 100644
index 0000000..b46df84
--- /dev/null
+++ b/test/types/exports.tsx
@@ -0,0 +1,7 @@
+import { domToReact, htmlToDOM } from 'html-react-parser';
+
+// $ExpectType (Element | Text | Comment | ProcessingInstruction)[]
+const domNodes = htmlToDOM('<div>text</div>');
+
+// $ExpectType string | Element | Element[]
+domToReact(domNodes);
diff --git a/test/types/index.tsx b/test/types/index.tsx
index 274fcd3..776e8ff 100644
--- a/test/types/index.tsx
+++ b/test/types/index.tsx
@@ -1,13 +1,4 @@
-import parse, {
-  Element,
-  HTMLReactParserOptions,
-  domToReact,
-  htmlToDOM
-} from 'html-react-parser';
-import * as React from 'react';
-
-// $ExpectError
-parse();
+import parse from 'html-react-parser';
 
 // $ExpectType string | Element | Element[]
 parse('');
@@ -20,74 +11,3 @@ parse('<p>text</p>');
 
 // $ExpectType string | Element | Element[]
 parse('<li>1</li><li>2</li>');
-
-// $ExpectType string | Element | Element[]
-parse('<br id="replace">', {
-  replace: domNode => {
-    if (domNode instanceof Element && domNode.attribs.id === 'replace') {
-      return <span>replaced</span>;
-    }
-  }
-});
-
-// $ExpectType string | Element | Element[]
-parse('<br id="remove">', {
-  replace: domNode => {
-    if (domNode instanceof Element && domNode.attribs.id === 'remove') {
-      return <></>;
-    }
-  }
-});
-
-let options: HTMLReactParserOptions;
-
-options = {
-  replace: domNode => {
-    if (domNode instanceof Element && domNode.attribs.id === 'header') {
-      return;
-    }
-  }
-};
-
-options = {
-  replace: domNode => {
-    if (domNode instanceof Element) {
-      return <>{domToReact(domNode.children)}</>;
-    }
-  }
-};
-
-// $ExpectType string | Element | Element[]
-parse('<a id="header" href="#">Heading</a>', options);
-
-// $ExpectType string | Element | Element[]
-parse('<hr>', {
-  library: {
-    cloneElement: (element, props, children) =>
-      React.cloneElement(element, props, children),
-    createElement: (type, props, children) =>
-      React.createElement(type, props, children),
-    isValidElement: element => React.isValidElement(element)
-  }
-});
-
-// $ExpectType string | Element | Element[]
-parse('<p/><p/>', {
-  htmlparser2: {
-    xmlMode: true,
-    decodeEntities: true,
-    lowerCaseTags: false,
-    lowerCaseAttributeNames: false,
-    recognizeCDATA: true,
-    recognizeSelfClosing: true
-  }
-});
-
-// $ExpectType string | Element | Element[]
-parse('\t<p>text \r</p>\n', { trim: true });
-
-// $ExpectType (Element | Text | Comment | ProcessingInstruction)[]
-const domNodes = htmlToDOM('<div>text</div>');
-
-// $ExpectType string | Element | Element[]
-domToReact(domNodes);
diff --git a/test/types/options/htmlparser2.tsx b/test/types/options/htmlparser2.tsx
new file mode 100644
index 0000000..5f8f540
--- /dev/null
+++ b/test/types/options/htmlparser2.tsx
@@ -0,0 +1,13 @@
+import parse from 'html-react-parser';
+
+// $ExpectType string | Element | Element[]
+parse('<p/><p/>', {
+  htmlparser2: {
+    xmlMode: true,
+    decodeEntities: true,
+    lowerCaseTags: false,
+    lowerCaseAttributeNames: false,
+    recognizeCDATA: true,
+    recognizeSelfClosing: true
+  }
+});
diff --git a/test/types/options/library.tsx b/test/types/options/library.tsx
new file mode 100644
index 0000000..71e1fab
--- /dev/null
+++ b/test/types/options/library.tsx
@@ -0,0 +1,13 @@
+import parse from 'html-react-parser';
+import * as React from 'react';
+
+// $ExpectType string | Element | Element[]
+parse('<hr>', {
+  library: {
+    cloneElement: (element, props, children) =>
+      React.cloneElement(element, props, children),
+    createElement: (type, props, children) =>
+      React.createElement(type, props, children),
+    isValidElement: element => React.isValidElement(element)
+  }
+});
diff --git a/test/types/options/replace.tsx b/test/types/options/replace.tsx
new file mode 100644
index 0000000..588658b
--- /dev/null
+++ b/test/types/options/replace.tsx
@@ -0,0 +1,45 @@
+import parse, {
+  Element,
+  HTMLReactParserOptions,
+  domToReact
+} from 'html-react-parser';
+import * as React from 'react';
+
+// $ExpectType string | Element | Element[]
+parse('<br id="replace">', {
+  replace: domNode => {
+    if (domNode instanceof Element && domNode.attribs.id === 'replace') {
+      return <span>replaced</span>;
+    }
+  }
+});
+
+// $ExpectType string | Element | Element[]
+parse('<br id="remove">', {
+  replace: domNode => {
+    if (domNode instanceof Element && domNode.attribs.id === 'remove') {
+      return <></>;
+    }
+  }
+});
+
+let options: HTMLReactParserOptions;
+
+options = {
+  replace: domNode => {
+    if (domNode instanceof Element && domNode.attribs.id === 'header') {
+      return;
+    }
+  }
+};
+
+options = {
+  replace: domNode => {
+    if (domNode instanceof Element) {
+      return <>{domToReact(domNode.children)}</>;
+    }
+  }
+};
+
+// $ExpectType string | Element | Element[]
+parse('<a id="header" href="#">Heading</a>', options);
diff --git a/test/types/options/trim.tsx b/test/types/options/trim.tsx
new file mode 100644
index 0000000..6705594
--- /dev/null
+++ b/test/types/options/trim.tsx
@@ -0,0 +1,4 @@
+import parse from 'html-react-parser';
+
+// $ExpectType string | Element | Element[]
+parse('\t<p>text \r</p>\n', { trim: true });