diff --git a/lib/index.js b/lib/index.js
index 7696047..81aba70 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -206,7 +206,6 @@ export function MarkdownHooks(options) {
const [tree, setTree] = useState(/** @type {Root | undefined} */ (undefined))
useEffect(
- /* c8 ignore next 7 -- hooks are client-only. */
function () {
const file = createFile(options)
processor.run(processor.parse(file), file, function (error, tree) {
@@ -222,10 +221,8 @@ export function MarkdownHooks(options) {
]
)
- /* c8 ignore next -- hooks are client-only. */
if (error) throw error
- /* c8 ignore next -- hooks are client-only. */
return tree ? post(tree, options) : createElement(Fragment)
}
diff --git a/package.json b/package.json
index 4229029..4763e4a 100644
--- a/package.json
+++ b/package.json
@@ -62,6 +62,7 @@
},
"description": "React component to render markdown",
"devDependencies": {
+ "@testing-library/react": "^16.0.0",
"@types/node": "^22.0.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
@@ -69,6 +70,7 @@
"concat-stream": "^2.0.0",
"esbuild": "^0.25.0",
"eslint-plugin-react": "^7.0.0",
+ "global-jsdom": "^26.0.0",
"prettier": "^3.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
diff --git a/test.jsx b/test.jsx
index b59702f..8bbf4f7 100644
--- a/test.jsx
+++ b/test.jsx
@@ -1,13 +1,17 @@
/* @jsxRuntime automatic @jsxImportSource react */
/**
* @import {Root} from 'hast'
- * @import {ComponentProps} from 'react'
+ * @import {ComponentProps, ReactNode} from 'react'
* @import {ExtraProps} from 'react-markdown'
+ * @import {Plugin} from 'unified'
*/
import assert from 'node:assert/strict'
import test from 'node:test'
+import 'global-jsdom/register'
+import {render, waitFor} from '@testing-library/react'
import concatStream from 'concat-stream'
+import {Component} from 'react'
import {renderToPipeableStream, renderToStaticMarkup} from 'react-dom/server'
import Markdown, {MarkdownAsync, MarkdownHooks} from 'react-markdown'
import rehypeRaw from 'rehype-raw'
@@ -1106,39 +1110,119 @@ test('MarkdownAsync', async function (t) {
// Note: hooks are not supported on the “server”.
test('MarkdownHooks', async function (t) {
- await t.test('should support `MarkdownHooks` (1)', async function () {
- assert.equal(renderToStaticMarkup(
a
') }) await t.test( 'should support async plugins w/ `MarkdownHooks` (`rehype-starry-night`)', async function () { - return new Promise(function (resolve) { - renderToPipeableStream( -console.log(3.14)\n
'
+ )
}
)
+
+ await t.test('should support `MarkdownHooks` that error', async function () {
+ const plugin = deferPlugin()
+
+ const {container} = render(
+