Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function toJSX(node, parentNode = {}, options = {}) {
this.layout = ${layout || 'null'}
}
render() {
const { components = {}, ...props } = this.props
const { components, ...props } = this.props

return <MDXTag
name="wrapper"
Expand Down
18 changes: 14 additions & 4 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const prism = require('@mapbox/rehype-prism')
const math = require('remark-math')
const katex = require('rehype-katex')
const prettier = require('prettier')
const {MDXTag} = require('@mdx-js/tag')
const {MDXTag, MDXProvider} = require('@mdx-js/tag')
const React = require('react')
const {renderToStaticMarkup} = require('react-dom/server')

Expand Down Expand Up @@ -46,8 +46,18 @@ const renderWithReact = async mdxCode => {
)

const element = fn(React, ...Object.values(scope))
const components = {
h1: ({children}) =>
React.createElement('h1', {style: {color: 'tomato'}}, children)
}

const elementWithProvider = React.createElement(
MDXProvider,
{components},
element
)

return renderToStaticMarkup(element)
return renderToStaticMarkup(elementWithProvider)
}

it('Should output parseable JSX', async () => {
Expand All @@ -59,7 +69,7 @@ it('Should output parseable JSX', async () => {
it('Should be able to render JSX with React', async () => {
const result = await renderWithReact('# Hello, world!')

expect(result).toContain('<h1>Hello, world!</h1>')
expect(result).toContain('<h1 style="color:tomato">Hello, world!</h1>')
})

it('Should output parseable JSX when using < or >', async () => {
Expand Down Expand Up @@ -88,7 +98,7 @@ it('Should match sample blog post snapshot', async () => {
this.layout = null;
}
render() {
const { components = {}, ...props } = this.props;
const { components, ...props } = this.props;

return (
<MDXTag name=\\"wrapper\\" components={components}>
Expand Down