Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): Raise error if MDXRenderer receives un… (#16555)
Browse files Browse the repository at this point in the history
  • Loading branch information
johno authored and sidharthachatterjee committed Aug 13, 2019
1 parent 65c868c commit aa03d44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/gatsby-plugin-mdx/mdx-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = function MDXRenderer({
children,
...props
}) {
if (!children) {
throw new Error(`MDXRenderer expected to receive an MDX String in children. Instead, it received: ${children}`)
}

const mdxComponents = useMDXComponents(components);
const mdxScope = useMDXScope(scope);

Expand Down
10 changes: 10 additions & 0 deletions packages/gatsby-plugin-mdx/mdx-renderer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ describe("mdx-renderer", () => {

expect(result.toJSON()).toEqual({ type: "div", props: {}, children: null });
});

test("provides a useful error message when no mdx is passed", () => {
const expectedErrorMessage = 'MDXRenderer expected to receive an MDX String in children. Instead, it received: undefined';

const renderUndefined = () => {
TestRenderer.create(<MDXRenderer scope={{ React: React }} />);
}

expect(renderUndefined).toThrowError(expectedErrorMessage);
});
});

0 comments on commit aa03d44

Please sign in to comment.