diff options
author | 2025-06-05 14:25:23 +0000 | |
---|---|---|
committer | 2025-06-05 14:25:23 +0000 | |
commit | e586d7d704d475afe3373a1de6ae20d504f79d6d (patch) | |
tree | 7e3fa24807cebd48a86bd40f866d792181191ee9 /examples/container-with-vitest/test | |
download | astro-latest.tar.gz astro-latest.tar.zst astro-latest.zip |
Sync from a8e1c0a7402940e0fc5beef669522b315052df1blatest
Diffstat (limited to 'examples/container-with-vitest/test')
-rw-r--r-- | examples/container-with-vitest/test/Card.test.ts | 29 | ||||
-rw-r--r-- | examples/container-with-vitest/test/ReactWrapper.test.ts | 17 | ||||
-rw-r--r-- | examples/container-with-vitest/test/[locale].test.ts | 16 |
3 files changed, 62 insertions, 0 deletions
diff --git a/examples/container-with-vitest/test/Card.test.ts b/examples/container-with-vitest/test/Card.test.ts new file mode 100644 index 000000000..119087a36 --- /dev/null +++ b/examples/container-with-vitest/test/Card.test.ts @@ -0,0 +1,29 @@ +import { experimental_AstroContainer as AstroContainer } from 'astro/container'; +import { expect, test } from 'vitest'; +import Card from '../src/components/Card.astro'; +import CounterLight from '../src/components/CounterLight.astro'; + +test('Card with slots', async () => { + const container = await AstroContainer.create(); + const result = await container.renderToString(Card, { + slots: { + default: 'Card content', + }, + }); + + expect(result).toContain('This is a card'); + expect(result).toContain('Card content'); +}); + +test('Card with nested CounterLight', async () => { + const container = await AstroContainer.create(); + const counterLight = await container.renderToString(CounterLight, { props: { count: 1 } }); + const result = await container.renderToString(Card, { + slots: { + default: counterLight, + }, + }); + + expect(result).toContain('This is a card'); + expect(result).toContain(counterLight); +}); diff --git a/examples/container-with-vitest/test/ReactWrapper.test.ts b/examples/container-with-vitest/test/ReactWrapper.test.ts new file mode 100644 index 000000000..6adbff6cf --- /dev/null +++ b/examples/container-with-vitest/test/ReactWrapper.test.ts @@ -0,0 +1,17 @@ +import { loadRenderers } from 'astro:container'; +import { getContainerRenderer } from '@astrojs/react'; +import { experimental_AstroContainer as AstroContainer } from 'astro/container'; +import { expect, test } from 'vitest'; +import ReactWrapper from '../src/components/ReactWrapper.astro'; + +const renderers = await loadRenderers([getContainerRenderer()]); +const container = await AstroContainer.create({ + renderers, +}); + +test('ReactWrapper with react renderer', async () => { + const result = await container.renderToString(ReactWrapper); + + expect(result).toContain('Counter'); + expect(result).toContain('Count: <!-- -->5'); +}); diff --git a/examples/container-with-vitest/test/[locale].test.ts b/examples/container-with-vitest/test/[locale].test.ts new file mode 100644 index 000000000..db450df53 --- /dev/null +++ b/examples/container-with-vitest/test/[locale].test.ts @@ -0,0 +1,16 @@ +import { experimental_AstroContainer as AstroContainer } from 'astro/container'; +import { expect, test } from 'vitest'; +import Locale from '../src/pages/[locale].astro'; + +test('Dynamic route', async () => { + const container = await AstroContainer.create(); + // @ts-ignore + const result = await container.renderToString(Locale, { + params: { + locale: 'en', + }, + request: new Request('http://example.com/en'), + }); + + expect(result).toContain('Locale: en'); +}); |