Skip to content

Commit 68649ac

Browse files
committed
test: explicit error message for push tag
when push tag is missing name attribute value
1 parent 853e1d5 commit 68649ac

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/process-stacks.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {match} = require('posthtml/lib/api');
44
const {render} = require('posthtml-render');
5+
const {get} = require('lodash');
56

67
/**
78
* Process <push> tag
@@ -13,8 +14,12 @@ const {render} = require('posthtml-render');
1314
*/
1415
function processPushes(tree, content, push) {
1516
match.call(tree, {tag: push}, pushNode => {
17+
if (get(pushNode, 'attrs.name') === '') {
18+
throw new Error(`[components] <${push}> tag requires a value for the "name" attribute.`);
19+
}
20+
1621
if (!pushNode.attrs || !pushNode.attrs.name) {
17-
throw new Error(`[components] Push <${push}> tag must have an attribute "name".`);
22+
throw new Error(`[components] <${push}> tag requires a "name" attribute.`);
1823
}
1924

2025
if (!content[pushNode.attrs.name]) {

test/test-errors.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ test('Must fail when component is not found in defined namespace with strict mod
5959
await t.throwsAsync(async () => posthtml([plugin({root: './test/templates', strict: true, namespaces: [{name: 'empty-namespace', root: './test/templates/empty-namespace'}]})]).process(actual).then(result => clean(result.html)));
6060
});
6161

62-
test('Must fail when push tag missing name', async t => {
62+
test('Must fail when push tag missing name attribute', async t => {
6363
const actual = `<div><push></push></div>`;
6464

6565
await t.throwsAsync(async () => posthtml([plugin({root: './test/templates', strict: true})]).process(actual).then(result => clean(result.html)));
6666
});
67+
68+
test('Must fail when push tag missing name attribute value', async t => {
69+
const actual = `<div><push name></push></div>`;
70+
71+
await t.throwsAsync(async () => posthtml([plugin({root: './test/templates', strict: true})]).process(actual).then(result => clean(result.html)));
72+
});

0 commit comments

Comments
 (0)