Fix/check content type (#1754)

* test: add test case

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

* test: fix test
This commit is contained in:
Yoshiaki Togami 2021-11-10 02:46:01 +09:00 committed by GitHub
parent f22a5c45d8
commit 7acf762c12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -20,7 +20,7 @@ const { privateRenderMarkdownDoNotUse: renderMarkdown } = (Astro as any);
if (!content) { if (!content) {
const { privateRenderSlotDoNotUse: renderSlot } = (Astro as any); const { privateRenderSlotDoNotUse: renderSlot } = (Astro as any);
content = await renderSlot('default'); content = await renderSlot('default');
if (content.trim().length > 0) { if (content !== undefined && content !== null) {
content = dedent(content); content = dedent(content);
} }
} }

View file

@ -140,4 +140,10 @@ describe('Astro Markdown', () => {
// test Markdown rendered correctly via content prop // test Markdown rendered correctly via content prop
expect($('h1').text()).to.equal('Foo'); 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;
});
}); });

View file

@ -0,0 +1,5 @@
---
import { Markdown } from 'astro/components';
---
<Markdown></Markdown>