From cd9b32fa84062c10769398ad7e055394d4e69e5b Mon Sep 17 00:00:00 2001 From: Vlad Zhukov Date: Sat, 26 Mar 2022 13:15:25 +0400 Subject: [PATCH] Add one more test --- packages/mdx/test/compile.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/mdx/test/compile.js b/packages/mdx/test/compile.js index cfef96918..979af29e5 100644 --- a/packages/mdx/test/compile.js +++ b/packages/mdx/test/compile.js @@ -815,6 +815,28 @@ test('jsx', async () => { '}', '' ].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' )