Skip to content

How to test a custom code block component? #2233

Answered by wooorm
meganesu asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there Megan! :)

You are trying to use your component with MDX, but your tests don’t contain MDX.

In your test, you are only using JSX, to call your component (<CodeBlock>…</CodeBlock>), and you are choosing to pass it a single child (```js…```), which is just a string of text.

Your component does not accept a string as a child. Your component seems to only accept a single react node as a child, which is an element (props.children.props).

So React crashes: your test includes code that your component doesn’t accept. Your component crashes.

You can either change your test to be like something that MDX would pass.
Here’s roughly what MDX would generate:

<pre>
  <code className="language-js">{

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@remcohaszing
Comment options

@meganesu
Comment options

@wooorm
Comment options

@meganesu
Comment options

@DavidMikeSimon
Comment options

Answer selected by meganesu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants