@@ -7,34 +7,7 @@ var PlotlyInternal = require('@src/plotly');
7
7
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
8
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
9
9
var Plots = PlotlyInternal . Plots ;
10
-
11
- /* This is a one-off function to fully populate sparse arrays. This arises
12
- * because:
13
- *
14
- * var x = new Array(2)
15
- * expect(x).toEqual([undefined, undefined])
16
- *
17
- * will fail assertion even though x[0] === undefined and x[1] === undefined.
18
- * This is because the array elements don't exist until assigned.
19
- */
20
- function populateUndefinedArrayEls ( x ) {
21
- var i ;
22
- if ( Array . isArray ( x ) ) {
23
- for ( i = 0 ; i < x . length ; i ++ ) {
24
- x [ i ] = x [ i ] ;
25
- }
26
- } else if ( Lib . isPlainObject ( x ) ) {
27
- var keys = Object . keys ( x ) ;
28
- for ( i = 0 ; i < keys . length ; i ++ ) {
29
- populateUndefinedArrayEls ( x [ keys [ i ] ] ) ;
30
- }
31
- }
32
- }
33
-
34
- function expectLooseDeepEqual ( a , b ) {
35
- expect ( populateUndefinedArrayEls ( a ) ) . toEqual ( populateUndefinedArrayEls ( b ) ) ;
36
- }
37
-
10
+ var customMatchers = require ( '../assets/custom_matchers' ) ;
38
11
39
12
describe ( 'Test lib.js:' , function ( ) {
40
13
'use strict' ;
@@ -504,45 +477,50 @@ describe('Test lib.js:', function() {
504
477
} ) ;
505
478
506
479
describe ( 'expandObjectPaths' , function ( ) {
480
+ beforeAll ( function ( ) {
481
+ jasmine . addMatchers ( customMatchers ) ;
482
+ } ) ;
483
+
507
484
it ( 'returns the original object' , function ( ) {
508
485
var x = { } ;
509
486
expect ( Lib . expandObjectPaths ( x ) ) . toBe ( x ) ;
510
487
} ) ;
511
488
512
489
it ( 'unpacks top-level paths' , function ( ) {
513
490
var input = { 'marker.color' : 'red' , 'marker.size' : [ 1 , 2 , 3 ] } ;
514
- var expected = { marker : { color : 'red' , size : [ 1 , 2 , 3 ] } } ;
515
- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
491
+ var expected = { marker : { color : 'red' , size : [ 1 , 2 , 4 ] } } ;
492
+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
516
493
} ) ;
494
+ return ;
517
495
518
496
it ( 'unpacks recursively' , function ( ) {
519
497
var input = { 'marker.color' : { 'red.certainty' : 'definitely' } } ;
520
498
var expected = { marker : { color : { red : { certainty : 'definitely' } } } } ;
521
- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
499
+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
522
500
} ) ;
523
501
524
502
it ( 'unpacks deep paths' , function ( ) {
525
503
var input = { 'foo.bar.baz' : 'red' } ;
526
504
var expected = { foo : { bar : { baz : 'red' } } } ;
527
- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
505
+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
528
506
} ) ;
529
507
530
508
it ( 'unpacks non-top-level deep paths' , function ( ) {
531
509
var input = { color : { 'foo.bar.baz' : 'red' } } ;
532
510
var expected = { color : { foo : { bar : { baz : 'red' } } } } ;
533
- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
511
+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
534
512
} ) ;
535
513
536
514
it ( 'merges dotted properties into objects' , function ( ) {
537
515
var input = { marker : { color : 'red' } , 'marker.size' : 8 } ;
538
516
var expected = { marker : { color : 'red' , size : 8 } } ;
539
- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
517
+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
540
518
} ) ;
541
519
542
520
it ( 'merges objects into dotted properties' , function ( ) {
543
521
var input = { 'marker.size' : 8 , marker : { color : 'red' } } ;
544
522
var expected = { marker : { color : 'red' , size : 8 } } ;
545
- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
523
+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
546
524
} ) ;
547
525
548
526
it ( 'retains the identity of nested objects' , function ( ) {
@@ -568,49 +546,49 @@ describe('Test lib.js:', function() {
568
546
it ( 'expands bracketed array notation' , function ( ) {
569
547
var input = { 'marker[1]' : { color : 'red' } } ;
570
548
var expected = { marker : [ undefined , { color : 'red' } ] } ;
571
- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
549
+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
572
550
} ) ;
573
551
574
552
it ( 'expands nested arrays' , function ( ) {
575
553
var input = { 'marker[1].range[1]' : 5 } ;
576
554
var expected = { marker : [ undefined , { range : [ undefined , 5 ] } ] } ;
577
555
var computed = Lib . expandObjectPaths ( input ) ;
578
- expectLooseDeepEqual ( computed , expected ) ;
556
+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
579
557
} ) ;
580
558
581
559
it ( 'expands bracketed array with more nested attributes' , function ( ) {
582
560
var input = { 'marker[1]' : { 'color.alpha' : 2 } } ;
583
561
var expected = { marker : [ undefined , { color : { alpha : 2 } } ] } ;
584
562
var computed = Lib . expandObjectPaths ( input ) ;
585
- expectLooseDeepEqual ( computed , expected ) ;
563
+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
586
564
} ) ;
587
565
588
566
it ( 'expands bracketed array notation without further nesting' , function ( ) {
589
567
var input = { 'marker[1]' : 8 } ;
590
568
var expected = { marker : [ undefined , 8 ] } ;
591
569
var computed = Lib . expandObjectPaths ( input ) ;
592
- expectLooseDeepEqual ( computed , expected ) ;
570
+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
593
571
} ) ;
594
572
595
573
it ( 'expands bracketed array notation with further nesting' , function ( ) {
596
574
var input = { 'marker[1].size' : 8 } ;
597
575
var expected = { marker : [ undefined , { size : 8 } ] } ;
598
576
var computed = Lib . expandObjectPaths ( input ) ;
599
- expectLooseDeepEqual ( computed , expected ) ;
577
+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
600
578
} ) ;
601
579
602
580
it ( 'expands bracketed array notation with further nesting' , function ( ) {
603
581
var input = { 'marker[1].size.magnitude' : 8 } ;
604
582
var expected = { marker : [ undefined , { size : { magnitude : 8 } } ] } ;
605
583
var computed = Lib . expandObjectPaths ( input ) ;
606
- expectLooseDeepEqual ( computed , expected ) ;
584
+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
607
585
} ) ;
608
586
609
587
it ( 'combines changes with single array nesting' , function ( ) {
610
588
var input = { 'marker[1].foo' : 5 , 'marker[0].foo' : 4 } ;
611
589
var expected = { marker : [ { foo : 4 } , { foo : 5 } ] } ;
612
590
var computed = Lib . expandObjectPaths ( input ) ;
613
- expectLooseDeepEqual ( computed , expected ) ;
591
+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
614
592
} ) ;
615
593
616
594
// TODO: This test is unimplemented since it's a currently-unused corner case.
0 commit comments