astro-children.test.js — astro Source File
Architecture documentation for astro-children.test.js, a javascript file in the astro codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 23ce7a62_4e18_56ba_68ac_20443ce5c2c8["astro-children.test.js"] 0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"] 23ce7a62_4e18_56ba_68ac_20443ce5c2c8 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15 dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"] 23ce7a62_4e18_56ba_68ac_20443ce5c2c8 --> dd4f09ce_3fd7_8295_f616_8876cda4555c e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"] 23ce7a62_4e18_56ba_68ac_20443ce5c2c8 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607 6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"] 23ce7a62_4e18_56ba_68ac_20443ce5c2c8 --> 6b0635f9_51ea_77aa_767b_7857878e98a6 deb87372_5629_35f8_9a54_e755a08f776a["cheerio"] 23ce7a62_4e18_56ba_68ac_20443ce5c2c8 --> deb87372_5629_35f8_9a54_e755a08f776a style 23ce7a62_4e18_56ba_68ac_20443ce5c2c8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Component children', () => {
let fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-children/' });
await fixture.build();
});
it('Passes string children to framework components', async () => {
const html = await fixture.readFile('/strings/index.html');
const $ = cheerio.load(html);
// test 1: Can pass text to Preact components
const $preact = $('#preact');
assert.equal($preact.text().trim(), 'Hello world');
// test 2: Can pass text to Vue components
const $vue = $('#vue');
assert.equal($vue.text().trim(), 'Hello world');
// test 3: Can pass text to Svelte components
const $svelte = $('#svelte');
assert.equal($svelte.text().trim(), 'Hello world');
});
it('Passes markup children to framework components', async () => {
const html = await fixture.readFile('/markup/index.html');
const $ = cheerio.load(html);
// test 1: Can pass markup to Preact components
const $preact = $('#preact h1');
assert.equal($preact.text().trim(), 'Hello world');
// test 2: Can pass markup to Vue components
const $vue = $('#vue h1');
assert.equal($vue.text().trim(), 'Hello world');
// test 3: Can pass markup to Svelte components
const $svelte = $('#svelte h1');
assert.equal($svelte.text().trim(), 'Hello world');
});
it('Passes multiple children to framework components', async () => {
const html = await fixture.readFile('/multiple/index.html');
const $ = cheerio.load(html);
// test 1: Can pass multiple children to Preact components
const $preact = $('#preact');
assert.equal($preact.children().length, 2);
assert.equal($preact.children(':first-child').text().trim(), 'Hello world');
assert.equal($preact.children(':last-child').text().trim(), 'Goodbye world');
// test 2: Can pass multiple children to Vue components
const $vue = $('#vue');
assert.equal($vue.children().length, 2);
assert.equal($vue.children(':first-child').text().trim(), 'Hello world');
assert.equal($vue.children(':last-child').text().trim(), 'Goodbye world');
// test 3: Can pass multiple children to Svelte components
const $svelte = $('#svelte');
assert.equal($svelte.children().length, 2);
assert.equal($svelte.children(':first-child').text().trim(), 'Hello world');
assert.equal($svelte.children(':last-child').text().trim(), 'Goodbye world');
});
it('Renders a template when children are not rendered for client components', async () => {
const html = await fixture.readFile('/no-render/index.html');
const $ = cheerio.load(html);
// test 1: If SSR only, no children are rendered.
assert.equal($('#ssr-only').children().length, 0);
// test 2: If client, and no children are rendered, a template is.
assert.equal(
$('#client').parent().children().length,
2,
'rendered the client component and a template',
);
assert.equal(
$('#client').parent().find('template[data-astro-template]').length,
1,
'Found 1 template',
);
// test 3: If client, and children are rendered, no template is.
assert.equal($('#client-render').parent().children().length, 1);
assert.equal($('#client-render').parent().find('template').length, 0);
// test 4: If client and no children are provided, no template is.
assert.equal($('#client-no-children').parent().children().length, 1);
assert.equal($('#client-no-children').parent().find('template').length, 0);
});
});
Domain
Dependencies
- cheerio
- loadFixture
- node:test
- strict
- test-utils.js
Source
Frequently Asked Questions
What does astro-children.test.js do?
astro-children.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does astro-children.test.js depend on?
astro-children.test.js imports 5 module(s): cheerio, loadFixture, node:test, strict, test-utils.js.
Where is astro-children.test.js in the architecture?
astro-children.test.js is located at packages/astro/test/astro-children.test.js (domain: IntegrationAdapters, directory: packages/astro/test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free