@@ -55,6 +55,44 @@ describe('Pie defaults', function() {
5555 expect ( out . visible ) . toBe ( false ) ;
5656 } ) ;
5757
58+ it ( 'allows falsy json values to skip but does not allow bad values and zero sum' , function ( ) {
59+ var out ;
60+
61+ [ null , 0 , '' , false ] . forEach ( function ( e ) {
62+ out = _supply ( { type : 'pie' , values : [ 1 , e , 3 ] } ) ;
63+ expect ( out . visible ) . toBe ( true , e ) ;
64+ expect ( out . _length ) . toBe ( 3 , e ) ;
65+
66+ out = _supply ( { type : 'pie' , values : [ 1 , e ] } ) ;
67+ expect ( out . visible ) . toBe ( true , e ) ;
68+ expect ( out . _length ) . toBe ( 2 , e ) ;
69+
70+ out = _supply ( { type : 'pie' , values : [ 0 , e ] } ) ;
71+ expect ( out . visible ) . toBe ( false , e ) ;
72+ expect ( out . _length ) . toBe ( undefined , e ) ;
73+
74+ out = _supply ( { type : 'pie' , values : [ e ] } ) ;
75+ expect ( out . visible ) . toBe ( false , e ) ;
76+ expect ( out . _length ) . toBe ( undefined , e ) ;
77+ } ) ;
78+
79+ [ 'not a positive value' , '-1' , - 1 , NaN , - Infinity , undefined ] . forEach ( function ( e ) {
80+ out = _supply ( { type : 'pie' , values : [ 0 , e ] } ) ;
81+ expect ( out . visible ) . toBe ( false , e ) ;
82+ expect ( out . _length ) . toBe ( undefined , e ) ;
83+
84+ out = _supply ( { type : 'pie' , values : [ 1 , e ] } ) ;
85+ expect ( out . visible ) . toBe ( false , e ) ;
86+ expect ( out . _length ) . toBe ( undefined , e ) ;
87+ } ) ;
88+
89+ [ '1' , '+1' , '1e1' ] . forEach ( function ( e ) {
90+ out = _supply ( { type : 'pie' , values : [ 0 , e ] } ) ;
91+ expect ( out . visible ) . toBe ( true , e ) ;
92+ expect ( out . _length ) . toBe ( 2 , e ) ;
93+ } ) ;
94+ } ) ;
95+
5896 it ( 'is marked invisible if either labels or values is empty' , function ( ) {
5997 var out = _supply ( { type : 'pie' , labels : [ ] , values : [ 1 , 2 ] } ) ;
6098 expect ( out . visible ) . toBe ( false ) ;
0 commit comments