@@ -340,11 +340,12 @@ describe('Test lib.js:', function() {
340
340
} ) ;
341
341
342
342
it ( 'should access properties of objects in an array with index -1' , function ( ) {
343
- var obj = { arr : [ { a : 1 } , { a : 2 } , { b : 3 } ] } ;
343
+ var obj = { arr : [ { a : 1 } , { a : null } , { b : 3 } ] } ;
344
344
var prop = np ( obj , 'arr[-1].a' ) ;
345
345
346
- expect ( prop . get ( ) ) . toEqual ( [ 1 , 2 , undefined ] ) ;
347
- expect ( obj ) . toEqual ( { arr : [ { a : 1 } , { a : 2 } , { b : 3 } ] } ) ;
346
+ expect ( prop . get ( ) ) . toEqual ( [ 1 , undefined , undefined ] ) ;
347
+ expect ( prop . get ( true ) ) . toEqual ( [ 1 , null , undefined ] ) ;
348
+ expect ( obj ) . toEqual ( { arr : [ { a : 1 } , { a : null } , { b : 3 } ] } ) ;
348
349
349
350
prop . set ( 5 ) ;
350
351
expect ( prop . get ( ) ) . toBe ( 5 ) ;
@@ -2443,6 +2444,14 @@ describe('Test lib.js:', function() {
2443
2444
it ( 'should work with the number *0* (nested case)' , function ( ) {
2444
2445
expect ( Lib . templateString ( '%{x.y}' , { x : { y : 0 } } ) ) . toEqual ( '0' ) ;
2445
2446
} ) ;
2447
+
2448
+ it ( 'preserves null and NaN' , function ( ) {
2449
+ expect ( Lib . templateString (
2450
+ '%{a} %{b} %{c.d} %{c.e} %{f[0]} %{f[1]}' ,
2451
+ { a : null , b : NaN , c : { d : null , e : NaN } , f : [ null , NaN ] }
2452
+ ) )
2453
+ . toEqual ( 'null NaN null NaN null NaN' ) ;
2454
+ } ) ;
2446
2455
} ) ;
2447
2456
2448
2457
describe ( 'hovertemplateString' , function ( ) {
@@ -2471,6 +2480,16 @@ describe('Test lib.js:', function() {
2471
2480
expect ( Lib . hovertemplateString ( '%{x.y}' , { } , locale , { x : { y : 0 } } ) ) . toEqual ( '0' ) ;
2472
2481
} ) ;
2473
2482
2483
+ it ( 'preserves null and NaN' , function ( ) {
2484
+ expect ( Lib . hovertemplateString (
2485
+ '%{a} %{b} %{c.d} %{c.e} %{f[0]} %{f[1]}' ,
2486
+ { } ,
2487
+ locale ,
2488
+ { a : null , b : NaN , c : { d : null , e : NaN } , f : [ null , NaN ] }
2489
+ ) )
2490
+ . toEqual ( 'null NaN null NaN null NaN' ) ;
2491
+ } ) ;
2492
+
2474
2493
it ( 'subtitutes multiple matches' , function ( ) {
2475
2494
expect ( Lib . hovertemplateString ( 'foo %{group} %{trace}' , { } , locale , { group : 'asdf' , trace : 'jkl;' } ) ) . toEqual ( 'foo asdf jkl;' ) ;
2476
2495
} ) ;
@@ -2537,6 +2556,16 @@ describe('Test lib.js:', function() {
2537
2556
expect ( Lib . texttemplateString ( 'y: %{y}' , { yLabel : '0.1' } , locale , { y : 0.123 } ) ) . toEqual ( 'y: 0.1' ) ;
2538
2557
} ) ;
2539
2558
2559
+ it ( 'preserves null and NaN' , function ( ) {
2560
+ expect ( Lib . texttemplateString (
2561
+ '%{a} %{b} %{c.d} %{c.e} %{f[0]} %{f[1]}' ,
2562
+ { } ,
2563
+ locale ,
2564
+ { a : null , b : NaN , c : { d : null , e : NaN } , f : [ null , NaN ] }
2565
+ ) )
2566
+ . toEqual ( 'null NaN null NaN null NaN' ) ;
2567
+ } ) ;
2568
+
2540
2569
it ( 'warns user up to 10 times if a variable cannot be found' , function ( ) {
2541
2570
spyOn ( Lib , 'warn' ) . and . callThrough ( ) ;
2542
2571
Lib . texttemplateString ( '%{idontexist}' , { } ) ;
0 commit comments