@@ -240,28 +240,56 @@ describe('Plots.computeAPICommandBindings', function() {
240240 } ) ;
241241
242242 it ( 'with an array value' , function ( ) {
243- var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , [ 7 ] , [ 1 ] ] ) ;
243+ var value = [ 7 ] ;
244+ var traces = [ 1 ] ;
245+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , value , traces ] ) ;
244246 expect ( result ) . toEqual ( [ { prop : 'marker.size' , traces : [ 1 ] , type : 'data' , value : [ 7 ] } ] ) ;
247+ expect ( result [ 0 ] . value ) . not . toBe ( value , 'should not mutate value array' ) ;
248+ expect ( result [ 0 ] . traces ) . not . toBe ( traces , 'should not mutate traces array' ) ;
245249 } ) ;
246250
247251 it ( 'with two array values and two traces specified' , function ( ) {
248- var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , [ 7 , 5 ] , [ 0 , 1 ] ] ) ;
252+ var value = [ 7 , 5 ] ;
253+ var traces = [ 0 , 1 ] ;
254+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , value , traces ] ) ;
249255 expect ( result ) . toEqual ( [ { prop : 'marker.size' , traces : [ 0 , 1 ] , type : 'data' , value : [ 7 , 5 ] } ] ) ;
256+ expect ( result [ 0 ] . value ) . not . toBe ( value , 'should not mutate value array' ) ;
257+ expect ( result [ 0 ] . traces ) . not . toBe ( traces , 'should not mutate traces array' ) ;
250258 } ) ;
251259
252260 it ( 'with traces specified in reverse order' , function ( ) {
253- var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , [ 7 , 5 ] , [ 1 , 0 ] ] ) ;
261+ var value = [ 7 , 5 ] ;
262+ var traces = [ 1 , 0 ] ;
263+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , value , traces ] ) ;
254264 expect ( result ) . toEqual ( [ { prop : 'marker.size' , traces : [ 1 , 0 ] , type : 'data' , value : [ 7 , 5 ] } ] ) ;
265+ expect ( result [ 0 ] . value ) . not . toBe ( value , 'should not mutate value array' ) ;
266+ expect ( result [ 0 ] . traces ) . not . toBe ( traces , 'should not mutate traces array' ) ;
255267 } ) ;
256268
257269 it ( 'with two values and a single trace specified' , function ( ) {
258- var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , [ 7 , 5 ] , [ 0 ] ] ) ;
270+ var value = [ 7 , 5 ] ;
271+ var traces = [ 0 ] ;
272+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , value , traces ] ) ;
259273 expect ( result ) . toEqual ( [ { prop : 'marker.size' , traces : [ 0 ] , type : 'data' , value : [ 7 ] } ] ) ;
274+ expect ( result [ 0 ] . value ) . not . toBe ( value , 'should not mutate value array' ) ;
275+ expect ( result [ 0 ] . traces ) . not . toBe ( traces , 'should not mutate traces array' ) ;
260276 } ) ;
261277
262278 it ( 'with two values and a different trace specified' , function ( ) {
263- var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , [ 7 , 5 ] , [ 1 ] ] ) ;
279+ var value = [ 7 , 5 ] ;
280+ var traces = [ 1 ] ;
281+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , value , traces ] ) ;
264282 expect ( result ) . toEqual ( [ { prop : 'marker.size' , traces : [ 1 ] , type : 'data' , value : [ 7 ] } ] ) ;
283+ expect ( result [ 0 ] . value ) . not . toBe ( value , 'should not mutate value array' ) ;
284+ expect ( result [ 0 ] . traces ) . not . toBe ( traces , 'should not mutate traces array' ) ;
285+ } ) ;
286+
287+ it ( 'with two values and no trace specified' , function ( ) {
288+ gd . data . length = 0 ;
289+ var value = [ false , true ] ;
290+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'visible' , value ] ) ;
291+ expect ( result ) . toEqual ( [ { prop : 'visible' , traces : [ ] , type : 'data' , value : [ ] } ] ) ;
292+ expect ( result [ 0 ] . value ) . not . toBe ( value , 'should not mutate value array' ) ;
265293 } ) ;
266294 } ) ;
267295 } ) ;
0 commit comments