Skip to content

Commit

Permalink
test: add named slot test for frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Jun 20, 2022
1 parent 7b8c92a commit ef611cf
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 13 deletions.
4 changes: 1 addition & 3 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ Did you mean to add ${formatList(probableRendererNames.map((r) => '`' + r + '`')
const promises: Promise<void>[] = []
for (const [key, value] of Object.entries(slots)) {
promises.push(renderSlot(result, value as string).then((output) => {
if (output?.trim() !== '') {
children[key] = output;
}
children[key] = output;
}))
}
await Promise.all(promises);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h, Fragment } from 'preact';
import { useState } from 'preact/hooks'

export default function Counter({ children, count: initialCount, case: id }) {
export default function Counter({ named, children, count: initialCount, case: id }) {
const [count, setCount] = useState(initialCount);
const add = () => setCount((i) => i + 1);
const subtract = () => setCount((i) => i - 1);
Expand All @@ -15,6 +15,7 @@ export default function Counter({ children, count: initialCount, case: id }) {
</div>
<div id={id} className="counter-message">
{children || <h1>Fallback</h1>}
{named}
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import Counter from '../components/Counter.jsx'
<Counter case="false" client:visible>{false}</Counter>
<Counter case="string" client:visible>{''}</Counter>
<Counter case="content" client:visible><h1 id="slotted">Hello world!</h1></Counter>
<Counter case="named" client:visible><h1 slot="named"> / Named</h1></Counter>
</main>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';

export default function Counter({ children, count: initialCount, case: id }) {
export default function Counter({ named, children, count: initialCount, case: id }) {
const [count, setCount] = useState(initialCount);
const add = () => setCount((i) => i + 1);
const subtract = () => setCount((i) => i - 1);
Expand All @@ -14,6 +14,7 @@ export default function Counter({ children, count: initialCount, case: id }) {
</div>
<div id={id} className="counter-message">
{children || <h1>Fallback</h1>}
{named}
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import Counter from '../components/Counter.jsx'
<Counter case="false" client:visible>{false}</Counter>
<Counter case="string" client:visible>{''}</Counter>
<Counter case="content" client:visible><h1 id="slotted">Hello world!</h1></Counter>
<Counter case="named" client:visible><h1 slot="named"> / Named</h1></Counter>
</main>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSignal } from 'solid-js';

export default function Counter({ children, count: initialCount, case: id }) {
export default function Counter({ named, children, count: initialCount, case: id }) {
const [count] = createSignal(0);
return (
<>
Expand All @@ -9,6 +9,7 @@ export default function Counter({ children, count: initialCount, case: id }) {
</div>
<div id={id} className="counter-message">
{children || <h1>Fallback</h1>}
{named}
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import Counter from '../components/Counter.jsx'
<Counter case="false" client:visible>{false}</Counter>
<Counter case="string" client:visible>{''}</Counter>
<Counter case="content" client:visible><h1 id="slotted">Hello world!</h1></Counter>
<Counter case="named" client:visible><h1 slot="named"> / Named</h1></Counter>
</main>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
<button on:click={add}>+</button>
</div>
<div id={id}>
<slot>
<h1 id="fallback">Fallback</h1>
</slot>
<slot><h1 id="fallback">Fallback</h1></slot><slot name="named"></slot>
</div>

<style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import Counter from '../components/Counter.svelte'
<main>
<Counter id="default-self-closing" client:visible/>
<Counter id="default-empty" client:visible></Counter>
<Counter case="zero" client:visible>{0}</Counter>
<Counter case="false" client:visible>{false}</Counter>
<Counter case="string" client:visible>{''}</Counter>
<Counter id="zero" client:visible>{0}</Counter>
<Counter id="false" client:visible>{false}</Counter>
<Counter id="string" client:visible>{''}</Counter>
<Counter id="content" client:visible><h1 id="slotted">Hello world!</h1></Counter>
<Counter id="named" client:visible><h1 slot="named"> / Named</h1></Counter>
</main>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<slot>
<h1>Fallback</h1>
</slot>
<slot name="named" />
</div>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import Counter from '../components/Counter.vue'
<Counter case="false" client:visible>{false}</Counter>
<Counter case="string" client:visible>{''}</Counter>
<Counter case="content" client:visible><h1 id="slotted">Hello world!</h1></Counter>
<Counter case="named" client:visible><h1 slot="named"> / Named</h1></Counter>
</main>
6 changes: 6 additions & 0 deletions packages/astro/test/slots-preact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ describe('Slots: Preact', () => {
expect($('#string').text().trim()).to.equal('');
expect($('#content').text().trim()).to.equal('Hello world!');
});

it('Renders named slot', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named');
})
});
6 changes: 6 additions & 0 deletions packages/astro/test/slots-react.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ describe('Slots: React', () => {
expect($('#string').text().trim()).to.equal('');
expect($('#content').text().trim()).to.equal('Hello world!');
});

it('Renders named slot', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named');
})
});
6 changes: 6 additions & 0 deletions packages/astro/test/slots-solid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ describe('Slots: Solid', () => {
expect($('#string').text().trim()).to.equal('');
expect($('#content').text().trim()).to.equal('Hello world!');
});

it('Renders named slot', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named');
})
});
8 changes: 7 additions & 1 deletion packages/astro/test/slots-svelte.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ describe('Slots: Svelte', () => {

expect($('#default-self-closing').text().trim()).to.equal('Fallback');
expect($('#default-empty').text().trim()).to.equal('Fallback');
expect($('#zero').text().trim()).to.equal('');
expect($('#zero').text().trim()).to.equal('0');
expect($('#false').text().trim()).to.equal('');
expect($('#string').text().trim()).to.equal('');
expect($('#content').text().trim()).to.equal('Hello world!');
});

it('Renders named slot', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named');
})
});
6 changes: 6 additions & 0 deletions packages/astro/test/slots-vue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ describe('Slots: Vue', () => {
expect($('#string').text().trim()).to.equal('');
expect($('#content').text().trim()).to.equal('Hello world!');
});

it('Renders named slot', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named');
})
});

0 comments on commit ef611cf

Please sign in to comment.