Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 27, 2024
1 parent d3949b2 commit 3caee8a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/astro/test/container.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
renderComponent,
renderHead,
renderSlot,
createHeadAndContent,
renderTemplate
} from '../dist/runtime/server/index.js';

const BaseLayout = createComponent((result, _props, slots) => {
Expand Down Expand Up @@ -140,6 +142,54 @@ describe('Container', () => {
assert.match(result, /Bar name/);
});

it('Renders content and head component', async () => {
const Page = createComponent(
(result, _props, slots) => {

return createHeadAndContent(
'',
renderTemplate`${renderComponent(
result,
'BaseLayout',
BaseLayout,
{},
{
default: () => render`
${maybeRenderHead(result)}
${renderSlot(result, slots['custom-name'])}
${renderSlot(result, slots['foo-name'])}
`,
head: () => render`
${renderComponent(
result,
'Fragment',
Fragment,
{ slot: 'head' },
{
default: () => render`<meta charset="utf-8">`,
}
)}
`,
}
)}`
);
},
'Component2.astro',
undefined
);

const container = await experimental_AstroContainer.create();
const result = await container.renderToString(Page, {
slots: {
'custom-name': 'Custom name',
'foo-name': 'Bar name',
},
});

assert.match(result, /Custom name/);
assert.match(result, /Bar name/);
});

it('Renders props', async () => {
const Page = createComponent(
(result, props, _slots) => {
Expand Down

0 comments on commit 3caee8a

Please sign in to comment.