diff --git a/src/js/NodeModel.js b/src/js/NodeModel.js index 8058f336..6d58e691 100644 --- a/src/js/NodeModel.js +++ b/src/js/NodeModel.js @@ -52,7 +52,7 @@ class NodeModel { } nodeHasChildren(node) { - return Array.isArray(node.children) && node.children.length > 0; + return Array.isArray(node.children); } getDisabledState(node, parent, disabledProp, noCascade) { diff --git a/test/CheckboxTree.js b/test/CheckboxTree.js index 17ba31a2..c9628fe9 100644 --- a/test/CheckboxTree.js +++ b/test/CheckboxTree.js @@ -181,6 +181,56 @@ describe('', () => { { children: [null, null] }, ); }); + + it('should render a node with no "children" array as a leaf', () => { + const wrapper = shallow( + , + ); + + assert.equal(false, wrapper.find(TreeNode).prop('isParent')); + assert.equal(true, wrapper.find(TreeNode).prop('isLeaf')); + }); + + it('should render a node with an empty "children" array as a parent', () => { + const wrapper = shallow( + , + ); + + assert.equal(true, wrapper.find(TreeNode).prop('isParent')); + assert.equal(false, wrapper.find(TreeNode).prop('isLeaf')); + }); + + it('should render a node with a non-empty "children" array as a parent', () => { + const wrapper = shallow( + , + ); + + assert.equal(true, wrapper.find(TreeNode).prop('isParent')); + assert.equal(false, wrapper.find(TreeNode).prop('isLeaf')); + }); }); describe('noCascade', () => {