@@ -240,28 +240,56 @@ describe('Plots.computeAPICommandBindings', function() {
240
240
} ) ;
241
241
242
242
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 ] ) ;
244
246
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' ) ;
245
249
} ) ;
246
250
247
251
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 ] ) ;
249
255
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' ) ;
250
258
} ) ;
251
259
252
260
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 ] ) ;
254
264
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' ) ;
255
267
} ) ;
256
268
257
269
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 ] ) ;
259
273
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' ) ;
260
276
} ) ;
261
277
262
278
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 ] ) ;
264
282
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' ) ;
265
293
} ) ;
266
294
} ) ;
267
295
} ) ;
0 commit comments