diff --git a/packages/mdx/test/compile.js b/packages/mdx/test/compile.js
index 979af29e5..5715f799a 100644
--- a/packages/mdx/test/compile.js
+++ b/packages/mdx/test/compile.js
@@ -504,6 +504,38 @@ test('compile', async () => {
)
}
+ try {
+ renderToStaticMarkup(
+ React.createElement(
+ await run(compileSync('export const a = {}\n\n'))
+ )
+ )
+ assert.unreachable()
+ } catch (/** @type {unknown} */ error) {
+ const exception = /** @type {Error} */ (error)
+ assert.match(
+ exception.message,
+ /Expected component `a.b` to be defined/,
+ 'should throw if a required member is not passed'
+ )
+ }
+
+ try {
+ renderToStaticMarkup(
+ React.createElement(
+ await run(compileSync(' } />'))
+ )
+ )
+ assert.unreachable()
+ } catch (/** @type {unknown} */ error) {
+ const exception = /** @type {Error} */ (error)
+ assert.match(
+ exception.message,
+ /x is not defined/,
+ 'should throw if a required member is not passed'
+ )
+ }
+
try {
renderToStaticMarkup(
React.createElement(await run(compileSync('', {development: true})))
@@ -791,55 +823,6 @@ test('jsx', async () => {
'should serialize fragments, namespaces, members'
)
- assert.equal(
- String(
- compileSync('export const a = {}\n\n', {
- jsx: true
- })
- ),
- [
- '/*@jsxRuntime automatic @jsxImportSource react*/',
- 'export const a = {};',
- 'function MDXContent(props = {}) {',
- ' const {wrapper: MDXLayout} = props.components || ({});',
- ' return MDXLayout ? <_createMdxContent /> : _createMdxContent();',
- ' function _createMdxContent() {',
- ' if (!a) _missingMdxReference("a", false);',
- ' if (!a.b) _missingMdxReference("a.b", true);',
- ' return ;',
- ' }',
- '}',
- 'export default MDXContent;',
- 'function _missingMdxReference(id, component) {',
- ' throw new Error("Expected " + (component ? "component" : "object") + " `" + id + "` to be defined: you likely forgot to import, pass, or provide it.");',
- '}',
- ''
- ].join('\n'),
- 'should always inject _missingMdxReference checks'
- )
-
- assert.equal(
- String(compileSync(' } />', {jsx: true})),
- [
- '/*@jsxRuntime automatic @jsxImportSource react*/',
- 'function MDXContent(props = {}) {',
- ' const {wrapper: MDXLayout} = props.components || ({});',
- ' return MDXLayout ? <_createMdxContent /> : _createMdxContent();',
- ' function _createMdxContent() {',
- ' if (!x) _missingMdxReference("x", false);',
- ' if (!x.y) _missingMdxReference("x.y", true);',
- ' return } />;',
- ' }',
- '}',
- 'export default MDXContent;',
- 'function _missingMdxReference(id, component) {',
- ' throw new Error("Expected " + (component ? "component" : "object") + " `" + id + "` to be defined: you likely forgot to import, pass, or provide it.");',
- '}',
- ''
- ].join('\n'),
- 'should serialize members inside expressions'
- )
-
assert.equal(
String(compileSync('<>a {/* 1 */} b>', {jsx: true})),
[