diff --git a/src/JSONLDAbstractNode.js b/src/JSONLDAbstractNode.js
index 2552c74..2431ea1 100644
--- a/src/JSONLDAbstractNode.js
+++ b/src/JSONLDAbstractNode.js
@@ -11,7 +11,13 @@ class JSONLDAbstractNode extends React.Component {
};
getChildJSON(child) {
- if (!child) return null;
+ if (!child) {
+ return null;
+ }
+
+ if (Array.isArray(child) && child.length === 0) {
+ return null;
+ }
const ChildClass = child.type;
const { children, type, id, ...schema } = child.props;
@@ -28,7 +34,9 @@ class JSONLDAbstractNode extends React.Component {
}
parseChildren() {
- if (!this.props.children) return {};
+ if (!this.props.children) {
+ return {};
+ }
/*
* If a component has a single child, this.props.children is a Child object.
* If a component has multiple children, this.props.children is an array of Child objects.
@@ -39,7 +47,8 @@ class JSONLDAbstractNode extends React.Component {
.map(child => this.getChildJSON(child))
.filter(child => child);
}
- return [this.getChildJSON(this.props.children)];
+ const childJSON = this.getChildJSON(this.props.children);
+ return childJSON ? [childJSON] : null;
}
render() {
diff --git a/src/core/__tests__/GenericNodeCollection.test.js b/src/core/__tests__/GenericNodeCollection.test.js
index 5f1c009..d632274 100644
--- a/src/core/__tests__/GenericNodeCollection.test.js
+++ b/src/core/__tests__/GenericNodeCollection.test.js
@@ -30,4 +30,34 @@ describe("GenerticNodeCollection", () => {
)
).toMatchSnapshot();
});
+ it("do not render empty collection", () => {
+ expect(
+ renderer.create(
+
+
+
+
+
+ )
+ ).toMatchSnapshot();
+ });
+ it("do not render collection of empty array in it", () => {
+ expect(
+ renderer.create(
+
+
+ {[]}
+
+
+ )
+ ).toMatchSnapshot();
+ });
});
diff --git a/src/core/__tests__/__snapshots__/GenericNodeCollection.test.js.snap b/src/core/__tests__/__snapshots__/GenericNodeCollection.test.js.snap
index 6902c43..5fdc830 100644
--- a/src/core/__tests__/__snapshots__/GenericNodeCollection.test.js.snap
+++ b/src/core/__tests__/__snapshots__/GenericNodeCollection.test.js.snap
@@ -1,5 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`GenerticNodeCollection do not render collection of empty array in it 1`] = `
+
+`;
+
+exports[`GenerticNodeCollection do not render empty collection 1`] = `
+
+`;
+
exports[`GenerticNodeCollection filters out null and false nodes from a collection 1`] = `