Skip to content

Commit

Permalink
Nested testing
Browse files Browse the repository at this point in the history
  • Loading branch information
thewebartisan7 committed Oct 16, 2022
1 parent 25259ef commit 44a6154
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions test/templates/components/nested-one-slot.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="nested-one">
<slot before></slot>
<slot></slot>
<slot after></slot>
</div>
5 changes: 5 additions & 0 deletions test/templates/components/nested-two-slot.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<slot before></slot>
<slot></slot>
<slot after></slot>
</div>
24 changes: 24 additions & 0 deletions test/test-nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const test = require('ava');
const plugin = require('../src');
const posthtml = require('posthtml');
const clean = html => html.replace(/(\n|\t)/g, '').trim();

test('Must process all nested component to html', async t => {
const actual = `<div><x-nested-one></x-nested-one></div>`;
const expected = `<div><div class="nested-one"><div class="nested-two"><div class="nested-three">Nested works!</div></div></div></div>`;

const html = await posthtml([plugin({root: './test/templates/components'})]).process(actual).then(result => clean(result.html));

t.is(html, expected);
});

test('Must process all nested component with slots to html', async t => {
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>`;
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>`;

const html = await posthtml([plugin({root: './test/templates/components'})]).process(actual).then(result => clean(result.html));

t.is(html, expected);
});
9 changes: 0 additions & 9 deletions test/test-x-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ test('Must process component to html', async t => {
t.is(html, expected);
});

test('Must process all nested component to html', async t => {
const actual = `<div><x-nested-one></x-nested-one></div>`;
const expected = `<div><div class="nested-one"><div class="nested-two"><div class="nested-three">Nested works!</div></div></div></div>`;

const html = await posthtml([plugin({root: './test/templates/components'})]).process(actual).then(result => clean(result.html));

t.is(html, expected);
});

test('Must process component with namespace to html', async t => {
const actual = `<x-dark::button><slot name="content">My button</slot></x-dark::button>`;
const expected = `<button class="bg-dark text-light">My button</button>`;
Expand Down

0 comments on commit 44a6154

Please sign in to comment.