@@ -445,26 +445,32 @@ describe('Working with dimensions', () => {
445445 } ) ;
446446
447447 it . each ( [
448- { value : undefined , name : 'undefined ' } ,
449- { value : null , name : 'null ' } ,
448+ { value : undefined , name : 'valid-name ' } ,
449+ { value : null , name : 'valid-name ' } ,
450450 {
451451 value : '' ,
452- name : 'empty string ' ,
452+ name : 'valid-name ' ,
453453 } ,
454- ] ) ( 'skips invalid dimension values ($name)' , ( { value } ) => {
454+ { value : 'valid-value' , name : undefined } ,
455+ { value : 'valid-value' , name : null } ,
456+ {
457+ value : 'valid-value' ,
458+ name : '' ,
459+ } ,
460+ ] ) ( 'skips invalid dimension values ($name)' , ( { value, name } ) => {
455461 // Prepare
456462 const metrics = new Metrics ( {
457463 singleMetric : true ,
458464 namespace : DEFAULT_NAMESPACE ,
459465 } ) ;
460466
461467 // Act & Assess
462- metrics . addDimension ( 'test' , value as string ) ;
468+ metrics . addDimension ( name as string , value as string ) ;
463469 metrics . addMetric ( 'test' , MetricUnit . Count , 1 ) ;
464470
465471 expect ( console . warn ) . toHaveBeenCalledTimes ( 1 ) ;
466472 expect ( console . warn ) . toHaveBeenCalledWith (
467- `The dimension test doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings`
473+ `The dimension ${ name } doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings`
468474 ) ;
469475 expect ( console . log ) . toHaveEmittedEMFWith (
470476 expect . not . objectContaining ( { test : value } )
@@ -475,37 +481,44 @@ describe('Working with dimensions', () => {
475481 } ) ;
476482
477483 it . each ( [
478- { value : undefined , name : 'undefined ' } ,
479- { value : null , name : 'null ' } ,
484+ { value : undefined , name : 'valid-name ' } ,
485+ { value : null , name : 'valid-name ' } ,
480486 {
481487 value : '' ,
482- name : 'empty string ' ,
488+ name : 'valid-name ' ,
483489 } ,
484- ] ) ( 'skips invalid dimension values in addDimensions ($name)' , ( { value } ) => {
485- // Prepare
486- const metrics = new Metrics ( {
487- singleMetric : true ,
488- namespace : DEFAULT_NAMESPACE ,
489- } ) ;
490-
491- // Act & Assess
492- metrics . addDimensions ( {
493- validDimension : 'valid' ,
494- invalidDimension : value as string ,
495- } ) ;
496- metrics . addMetric ( 'test' , MetricUnit . Count , 1 ) ;
497- metrics . publishStoredMetrics ( ) ;
498-
499- expect ( console . warn ) . toHaveBeenCalledWith (
500- `The dimension invalidDimension doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings`
501- ) ;
502- expect ( console . log ) . toHaveEmittedEMFWith (
503- expect . objectContaining ( { validDimension : 'valid' } )
504- ) ;
505- expect ( console . log ) . toHaveEmittedEMFWith (
506- expect . not . objectContaining ( { invalidDimension : value } )
507- ) ;
508- } ) ;
490+ {
491+ value : 'valid-value' ,
492+ name : '' ,
493+ } ,
494+ ] ) (
495+ 'skips invalid dimension values in addDimensions ($name)' ,
496+ ( { value, name } ) => {
497+ // Prepare
498+ const metrics = new Metrics ( {
499+ singleMetric : true ,
500+ namespace : DEFAULT_NAMESPACE ,
501+ } ) ;
502+
503+ // Act & Assess
504+ metrics . addDimensions ( {
505+ validDimension : 'valid' ,
506+ [ name as string ] : value as string ,
507+ } ) ;
508+ metrics . addMetric ( 'test' , MetricUnit . Count , 1 ) ;
509+ metrics . publishStoredMetrics ( ) ;
510+
511+ expect ( console . warn ) . toHaveBeenCalledWith (
512+ `The dimension ${ name } doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings`
513+ ) ;
514+ expect ( console . log ) . toHaveEmittedEMFWith (
515+ expect . objectContaining ( { validDimension : 'valid' } )
516+ ) ;
517+ expect ( console . log ) . toHaveEmittedEMFWith (
518+ expect . not . objectContaining ( { invalidDimension : value } )
519+ ) ;
520+ }
521+ ) ;
509522
510523 it ( 'warns when addDimensions overwrites existing dimensions' , ( ) => {
511524 // Prepare
0 commit comments