Skip to content

Commit

Permalink
Fix/check content type (#1754)
Browse files Browse the repository at this point in the history
* test: add test case

* fix: add type guard insted of content.trim().length > 0

* test: fix test
  • Loading branch information
togami2864 committed Nov 9, 2021
1 parent f22a5c4 commit 7acf762
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/astro/components/Markdown.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/test/astro-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
import { Markdown } from 'astro/components';
---

<Markdown></Markdown>

0 comments on commit 7acf762

Please sign in to comment.