Repository: remarkablemark/html-react-parser
Pull request #955 (2023-06-15 04:44:14)

test(module): refactor module tests
## What is the motivation for this pull request?

test(module): refactor module tests

## What is the current behavior?

Module test aren't really tests

## What is the new behavior?

Module tests follow testing practices

## Checklist:

- [x] [Conventional Commits](https://www.conventionalcommits.org/)
- [x] Tests
- [ ] Documentation
- [ ] Types


Patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index d49a2a0..f7cff19 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -24,10 +24,10 @@ jobs:
       - name: Lint TypeScript declaration files
         run: npm run lint:dts
 
-      - name: Run unit tests
+      - name: Run tests
         run: npm run test:ci
 
-      - name: Run ES modules tests
+      - name: Run module tests
         run: npm run test:module
 
       - name: Run integration tests
diff --git a/package.json b/package.json
index b578e59..8ec4837 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,7 @@
     "size-limit": "size-limit",
     "test": "jest --coverage --testPathIgnorePatterns test/integration/",
     "test:ci": "npm test -- --ci --colors",
-    "test:module": "node --experimental-modules test/module/index.mjs",
+    "test:module": "node --test test/module/",
     "test:integration": "npm run build && jest --env=jsdom test/integration/",
     "test:watch": "npm test -- --watch"
   },


Test patch:
diff --git a/test/module/index.mjs b/test/module/index.mjs
deleted file mode 100644
index dac2ca6..0000000
--- a/test/module/index.mjs
+++ /dev/null
@@ -1,16 +0,0 @@
-import assert from 'assert';
-import parse, {
-  attributesToProps,
-  domToReact,
-  htmlToDOM
-} from '../../index.mjs';
-import { Comment, Element, ProcessingInstruction, Text } from '../../index.mjs';
-
-[parse, domToReact, htmlToDOM, attributesToProps].forEach(func => {
-  assert.strictEqual(typeof func, 'function');
-});
-
-// domhandler
-[Comment, Element, ProcessingInstruction, Text].forEach(func => {
-  assert.strictEqual(typeof func, 'function');
-});
diff --git a/test/module/index.test.mjs b/test/module/index.test.mjs
new file mode 100644
index 0000000..fd5a48e
--- /dev/null
+++ b/test/module/index.test.mjs
@@ -0,0 +1,54 @@
+import { describe, it } from 'node:test';
+
+import assert from 'assert';
+import { isValidElement } from 'react';
+
+import parse, {
+  Comment,
+  Element,
+  ProcessingInstruction,
+  Text,
+  attributesToProps,
+  domToReact,
+  htmlToDOM
+} from '../../index.mjs';
+
+describe('index', () => {
+  it('exports "parse" function', () => {
+    assert.strictEqual(typeof parse, 'function');
+  });
+
+  it('parses HTML to React element', () => {
+    assert.ok(isValidElement(parse('<p>text</p>')));
+  });
+
+  it('exports "attributesToProps" function', () => {
+    assert.strictEqual(typeof attributesToProps, 'function');
+  });
+
+  it('exports "domToReact" function', () => {
+    assert.strictEqual(typeof domToReact, 'function');
+  });
+
+  it('exports "htmlToDOM" function', () => {
+    assert.strictEqual(typeof htmlToDOM, 'function');
+  });
+});
+
+describe('domhandler', () => {
+  it('exports "Comment" function', () => {
+    assert.strictEqual(typeof Comment, 'function');
+  });
+
+  it('exports "Element" function', () => {
+    assert.strictEqual(typeof Element, 'function');
+  });
+
+  it('exports "ProcessingInstruction" function', () => {
+    assert.strictEqual(typeof ProcessingInstruction, 'function');
+  });
+
+  it('exports "Text" function', () => {
+    assert.strictEqual(typeof Text, 'function');
+  });
+});