From 44a6154cd1237a0f2de3fd78cff11c4fba84eb1d Mon Sep 17 00:00:00 2001 From: Damir Date: Sun, 16 Oct 2022 08:32:42 +0200 Subject: [PATCH] Nested testing --- .../templates/components/nested-one-slot.html | 5 ++++ .../templates/components/nested-two-slot.html | 5 ++++ test/test-nested.js | 24 +++++++++++++++++++ test/test-x-tag.js | 9 ------- 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 test/templates/components/nested-one-slot.html create mode 100644 test/templates/components/nested-two-slot.html create mode 100644 test/test-nested.js diff --git a/test/templates/components/nested-one-slot.html b/test/templates/components/nested-one-slot.html new file mode 100644 index 0000000..b669f3b --- /dev/null +++ b/test/templates/components/nested-one-slot.html @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/test/templates/components/nested-two-slot.html b/test/templates/components/nested-two-slot.html new file mode 100644 index 0000000..03bed24 --- /dev/null +++ b/test/templates/components/nested-two-slot.html @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/test/test-nested.js b/test/test-nested.js new file mode 100644 index 0000000..1d4d390 --- /dev/null +++ b/test/test-nested.js @@ -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 = `
`; + const expected = `
Nested works!
`; + + 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 = `
nested-two contentnested-two beforenested-two afternested-one beforenested-one after
`; + const expected = `
nested-one before
nested-two before nested-two content nested-two after
nested-one after
`; + + const html = await posthtml([plugin({root: './test/templates/components'})]).process(actual).then(result => clean(result.html)); + + t.is(html, expected); +}); diff --git a/test/test-x-tag.js b/test/test-x-tag.js index 8e7853a..172b4e2 100644 --- a/test/test-x-tag.js +++ b/test/test-x-tag.js @@ -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 = `
`; - const expected = `
Nested works!
`; - - 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 = `My button`; const expected = ``;