Skip to content

Commit 44a6154

Browse files
Nested testing
1 parent 25259ef commit 44a6154

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="nested-one">
2+
<slot before></slot>
3+
<slot></slot>
4+
<slot after></slot>
5+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
<slot before></slot>
3+
<slot></slot>
4+
<slot after></slot>
5+
</div>

test/test-nested.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const test = require('ava');
4+
const plugin = require('../src');
5+
const posthtml = require('posthtml');
6+
const clean = html => html.replace(/(\n|\t)/g, '').trim();
7+
8+
test('Must process all nested component to html', async t => {
9+
const actual = `<div><x-nested-one></x-nested-one></div>`;
10+
const expected = `<div><div class="nested-one"><div class="nested-two"><div class="nested-three">Nested works!</div></div></div></div>`;
11+
12+
const html = await posthtml([plugin({root: './test/templates/components'})]).process(actual).then(result => clean(result.html));
13+
14+
t.is(html, expected);
15+
});
16+
17+
test('Must process all nested component with slots to html', async t => {
18+
const actual = `<div><x-nested-one-slot><x-nested-two-slot>nested-two content<slot before>nested-two before</slot><slot after>nested-two after</slot></x-nested-two-slot><slot before>nested-one before</slot><slot after>nested-one after</slot></x-nested-one-slot></div>`;
19+
const expected = `<div><div class="nested-one"> nested-one before <div> nested-two before nested-two content nested-two after</div> nested-one after</div></div>`;
20+
21+
const html = await posthtml([plugin({root: './test/templates/components'})]).process(actual).then(result => clean(result.html));
22+
23+
t.is(html, expected);
24+
});

test/test-x-tag.js

-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ test('Must process component to html', async t => {
1414
t.is(html, expected);
1515
});
1616

17-
test('Must process all nested component to html', async t => {
18-
const actual = `<div><x-nested-one></x-nested-one></div>`;
19-
const expected = `<div><div class="nested-one"><div class="nested-two"><div class="nested-three">Nested works!</div></div></div></div>`;
20-
21-
const html = await posthtml([plugin({root: './test/templates/components'})]).process(actual).then(result => clean(result.html));
22-
23-
t.is(html, expected);
24-
});
25-
2617
test('Must process component with namespace to html', async t => {
2718
const actual = `<x-dark::button><slot name="content">My button</slot></x-dark::button>`;
2819
const expected = `<button class="bg-dark text-light">My button</button>`;

0 commit comments

Comments
 (0)