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:
parent
f22a5c45d8
commit
7acf762c12
3 changed files with 12 additions and 1 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
5
packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro
vendored
Normal file
5
packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
import { Markdown } from 'astro/components';
|
||||||
|
---
|
||||||
|
|
||||||
|
<Markdown></Markdown>
|
Loading…
Reference in a new issue