@@ -336,7 +336,7 @@ describe('<CheckboxTree />', () => {
336336 ) ;
337337 } ) ;
338338
339- it ( 'should render a node with no " children" array as a leaf' , ( ) => {
339+ it ( 'should render a node with no ` children` array as a leaf' , ( ) => {
340340 const wrapper = shallow (
341341 < CheckboxTree
342342 nodes = { [
@@ -349,7 +349,7 @@ describe('<CheckboxTree />', () => {
349349 assert . equal ( true , wrapper . find ( TreeNode ) . prop ( 'isLeaf' ) ) ;
350350 } ) ;
351351
352- it ( 'should render a node with an empty " children" array as a parent' , ( ) => {
352+ it ( 'should render a node with an empty ` children` array as a parent' , ( ) => {
353353 const wrapper = shallow (
354354 < CheckboxTree
355355 nodes = { [
@@ -366,7 +366,24 @@ describe('<CheckboxTree />', () => {
366366 assert . equal ( false , wrapper . find ( TreeNode ) . prop ( 'isLeaf' ) ) ;
367367 } ) ;
368368
369- it ( 'should render a node with a non-empty "children" array as a parent' , ( ) => {
369+ // https://github.com/jakezatecky/react-checkbox-tree/issues/258
370+ it ( 'should render a node with an empty `children` array as unchecked by default' , ( ) => {
371+ const wrapper = shallow (
372+ < CheckboxTree
373+ nodes = { [
374+ {
375+ value : 'jupiter' ,
376+ label : 'Jupiter' ,
377+ children : [ ] ,
378+ } ,
379+ ] }
380+ /> ,
381+ ) ;
382+
383+ assert . equal ( false , wrapper . find ( TreeNode ) . prop ( 'checked' ) ) ;
384+ } ) ;
385+
386+ it ( 'should render a node with a non-empty `children` array as a parent' , ( ) => {
370387 const wrapper = shallow (
371388 < CheckboxTree
372389 nodes = { [
@@ -734,6 +751,38 @@ describe('<CheckboxTree />', () => {
734751 assert . deepEqual ( [ 'io' , 'europa' ] , actualChecked ) ;
735752 } ) ;
736753
754+ // https://github.com/jakezatecky/react-checkbox-tree/issues/258
755+ it ( 'should toggle a node with an empty `children` array' , ( ) => {
756+ let actualChecked = { } ;
757+ const makeEmptyParentNode = ( checked ) => (
758+ mount (
759+ < CheckboxTree
760+ nodes = { [
761+ {
762+ value : 'jupiter' ,
763+ label : 'Jupiter' ,
764+ children : [ ] ,
765+ } ,
766+ ] }
767+ checked = { checked }
768+ onCheck = { ( node ) => {
769+ actualChecked = node ;
770+ } }
771+ /> ,
772+ )
773+ ) ;
774+
775+ // Unchecked to checked
776+ let wrapper = makeEmptyParentNode ( [ ] ) ;
777+ wrapper . find ( 'TreeNode input[type="checkbox"]' ) . simulate ( 'click' ) ;
778+ assert . deepEqual ( [ 'jupiter' ] , actualChecked ) ;
779+
780+ // Checked to unchecked
781+ wrapper = makeEmptyParentNode ( [ 'jupiter' ] ) ;
782+ wrapper . find ( 'TreeNode input[type="checkbox"]' ) . simulate ( 'click' ) ;
783+ assert . deepEqual ( [ ] , actualChecked ) ;
784+ } ) ;
785+
737786 it ( 'should not add disabled children to the checked array' , ( ) => {
738787 let actualChecked = null ;
739788
0 commit comments