@@ -7,34 +7,7 @@ var PlotlyInternal = require('@src/plotly');
77var createGraphDiv = require ( '../assets/create_graph_div' ) ;
88var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
99var 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' ) ;
3811
3912describe ( 'Test lib.js:' , function ( ) {
4013 'use strict' ;
@@ -504,45 +477,50 @@ describe('Test lib.js:', function() {
504477 } ) ;
505478
506479 describe ( 'expandObjectPaths' , function ( ) {
480+ beforeAll ( function ( ) {
481+ jasmine . addMatchers ( customMatchers ) ;
482+ } ) ;
483+
507484 it ( 'returns the original object' , function ( ) {
508485 var x = { } ;
509486 expect ( Lib . expandObjectPaths ( x ) ) . toBe ( x ) ;
510487 } ) ;
511488
512489 it ( 'unpacks top-level paths' , function ( ) {
513490 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 ) ;
516493 } ) ;
494+ return ;
517495
518496 it ( 'unpacks recursively' , function ( ) {
519497 var input = { 'marker.color' : { 'red.certainty' : 'definitely' } } ;
520498 var expected = { marker : { color : { red : { certainty : 'definitely' } } } } ;
521- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
499+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
522500 } ) ;
523501
524502 it ( 'unpacks deep paths' , function ( ) {
525503 var input = { 'foo.bar.baz' : 'red' } ;
526504 var expected = { foo : { bar : { baz : 'red' } } } ;
527- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
505+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
528506 } ) ;
529507
530508 it ( 'unpacks non-top-level deep paths' , function ( ) {
531509 var input = { color : { 'foo.bar.baz' : 'red' } } ;
532510 var expected = { color : { foo : { bar : { baz : 'red' } } } } ;
533- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
511+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
534512 } ) ;
535513
536514 it ( 'merges dotted properties into objects' , function ( ) {
537515 var input = { marker : { color : 'red' } , 'marker.size' : 8 } ;
538516 var expected = { marker : { color : 'red' , size : 8 } } ;
539- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
517+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
540518 } ) ;
541519
542520 it ( 'merges objects into dotted properties' , function ( ) {
543521 var input = { 'marker.size' : 8 , marker : { color : 'red' } } ;
544522 var expected = { marker : { color : 'red' , size : 8 } } ;
545- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
523+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
546524 } ) ;
547525
548526 it ( 'retains the identity of nested objects' , function ( ) {
@@ -568,49 +546,49 @@ describe('Test lib.js:', function() {
568546 it ( 'expands bracketed array notation' , function ( ) {
569547 var input = { 'marker[1]' : { color : 'red' } } ;
570548 var expected = { marker : [ undefined , { color : 'red' } ] } ;
571- expectLooseDeepEqual ( Lib . expandObjectPaths ( input ) , expected ) ;
549+ expect ( Lib . expandObjectPaths ( input ) ) . toLooseDeepEqual ( expected ) ;
572550 } ) ;
573551
574552 it ( 'expands nested arrays' , function ( ) {
575553 var input = { 'marker[1].range[1]' : 5 } ;
576554 var expected = { marker : [ undefined , { range : [ undefined , 5 ] } ] } ;
577555 var computed = Lib . expandObjectPaths ( input ) ;
578- expectLooseDeepEqual ( computed , expected ) ;
556+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
579557 } ) ;
580558
581559 it ( 'expands bracketed array with more nested attributes' , function ( ) {
582560 var input = { 'marker[1]' : { 'color.alpha' : 2 } } ;
583561 var expected = { marker : [ undefined , { color : { alpha : 2 } } ] } ;
584562 var computed = Lib . expandObjectPaths ( input ) ;
585- expectLooseDeepEqual ( computed , expected ) ;
563+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
586564 } ) ;
587565
588566 it ( 'expands bracketed array notation without further nesting' , function ( ) {
589567 var input = { 'marker[1]' : 8 } ;
590568 var expected = { marker : [ undefined , 8 ] } ;
591569 var computed = Lib . expandObjectPaths ( input ) ;
592- expectLooseDeepEqual ( computed , expected ) ;
570+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
593571 } ) ;
594572
595573 it ( 'expands bracketed array notation with further nesting' , function ( ) {
596574 var input = { 'marker[1].size' : 8 } ;
597575 var expected = { marker : [ undefined , { size : 8 } ] } ;
598576 var computed = Lib . expandObjectPaths ( input ) ;
599- expectLooseDeepEqual ( computed , expected ) ;
577+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
600578 } ) ;
601579
602580 it ( 'expands bracketed array notation with further nesting' , function ( ) {
603581 var input = { 'marker[1].size.magnitude' : 8 } ;
604582 var expected = { marker : [ undefined , { size : { magnitude : 8 } } ] } ;
605583 var computed = Lib . expandObjectPaths ( input ) ;
606- expectLooseDeepEqual ( computed , expected ) ;
584+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
607585 } ) ;
608586
609587 it ( 'combines changes with single array nesting' , function ( ) {
610588 var input = { 'marker[1].foo' : 5 , 'marker[0].foo' : 4 } ;
611589 var expected = { marker : [ { foo : 4 } , { foo : 5 } ] } ;
612590 var computed = Lib . expandObjectPaths ( input ) ;
613- expectLooseDeepEqual ( computed , expected ) ;
591+ expect ( computed ) . toLooseDeepEqual ( expected ) ;
614592 } ) ;
615593
616594 // TODO: This test is unimplemented since it's a currently-unused corner case.
0 commit comments