From 7acf762c120a38a3cef4af597c116f0c37147311 Mon Sep 17 00:00:00 2001 From: Yoshiaki Togami <62130798+togami2864@users.noreply.github.com> Date: Wed, 10 Nov 2021 02:46:01 +0900 Subject: [PATCH] Fix/check content type (#1754) * test: add test case * fix: add type guard insted of content.trim().length > 0 * test: fix test --- packages/astro/components/Markdown.astro | 2 +- packages/astro/test/astro-markdown.test.js | 6 ++++++ .../fixtures/astro-markdown/src/pages/no-elements.astro | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro diff --git a/packages/astro/components/Markdown.astro b/packages/astro/components/Markdown.astro index 862b3a2d4..350b9c317 100644 --- a/packages/astro/components/Markdown.astro +++ b/packages/astro/components/Markdown.astro @@ -20,7 +20,7 @@ const { privateRenderMarkdownDoNotUse: renderMarkdown } = (Astro as any); if (!content) { const { privateRenderSlotDoNotUse: renderSlot } = (Astro as any); content = await renderSlot('default'); - if (content.trim().length > 0) { + if (content !== undefined && content !== null) { content = dedent(content); } } diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js index de3a1f996..0d6aae978 100644 --- a/packages/astro/test/astro-markdown.test.js +++ b/packages/astro/test/astro-markdown.test.js @@ -140,4 +140,10 @@ describe('Astro Markdown', () => { // test Markdown rendered correctly via content prop expect($('h1').text()).to.equal('Foo'); }); + + it("doesn't occurs TypeError when no elements", async () => { + const html = await fixture.readFile('/no-elements/index.html'); + // render html without error + expect(html).to.be.ok; + }); }); diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro new file mode 100644 index 000000000..d865e9046 --- /dev/null +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro @@ -0,0 +1,5 @@ +--- +import { Markdown } from 'astro/components'; +--- + + \ No newline at end of file