Skip to content

Commit aa03d44

Browse files
johnosidharthachatterjee
authored andcommitted
fix(gatsby-plugin-mdx): Raise error if MDXRenderer receives un… (#16555)
1 parent 65c868c commit aa03d44

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/gatsby-plugin-mdx/mdx-renderer.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module.exports = function MDXRenderer({
88
children,
99
...props
1010
}) {
11+
if (!children) {
12+
throw new Error(`MDXRenderer expected to receive an MDX String in children. Instead, it received: ${children}`)
13+
}
14+
1115
const mdxComponents = useMDXComponents(components);
1216
const mdxScope = useMDXScope(scope);
1317

packages/gatsby-plugin-mdx/mdx-renderer.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,14 @@ describe("mdx-renderer", () => {
1414

1515
expect(result.toJSON()).toEqual({ type: "div", props: {}, children: null });
1616
});
17+
18+
test("provides a useful error message when no mdx is passed", () => {
19+
const expectedErrorMessage = 'MDXRenderer expected to receive an MDX String in children. Instead, it received: undefined';
20+
21+
const renderUndefined = () => {
22+
TestRenderer.create(<MDXRenderer scope={{ React: React }} />);
23+
}
24+
25+
expect(renderUndefined).toThrowError(expectedErrorMessage);
26+
});
1727
});

0 commit comments

Comments
 (0)