@@ -21,6 +21,7 @@ import {
2121 evaluateQuestionItemExpression ,
2222 findAnswersForQuestion ,
2323 ITEM_KEY ,
24+ stripNonEnumerable ,
2425} from '../src/utils' ;
2526import {
2627 ParametersParameter ,
@@ -2833,3 +2834,51 @@ describe('findAnswersForQuestion', () => {
28332834 ) ;
28342835 } ) ;
28352836} ) ;
2837+
2838+ describe ( 'stripNonEnumerable' , ( ) => {
2839+ test ( 'works correctly for array without non-enums' , ( ) => {
2840+ expect ( stripNonEnumerable ( [ 1 , null , undefined ] ) ) . toStrictEqual ( [ 1 , null , undefined ] ) ;
2841+ } ) ;
2842+
2843+ test ( 'works correctly for array with non-enums' , ( ) => {
2844+ const arrWithNonEnum = [ 1 , 2 , 3 ] ;
2845+ Object . defineProperty ( arrWithNonEnum , '__path__' , {
2846+ value : 'non-enum-prop' ,
2847+ enumerable : false ,
2848+ } ) ;
2849+ expect ( stripNonEnumerable ( arrWithNonEnum ) ) . toStrictEqual ( [ 1 , 2 , 3 ] ) ;
2850+ } ) ;
2851+
2852+ test ( 'works correctly for object without non-enums' , ( ) => {
2853+ expect ( stripNonEnumerable ( { a : 1 , b : null , c : undefined } ) ) . toStrictEqual ( { a : 1 , b : null , c : undefined } ) ;
2854+ } ) ;
2855+
2856+ test ( 'works correctly for object with non-enums' , ( ) => {
2857+ const objWithNonEnum = { a : 1 , b : 2 , c : 3 } ;
2858+ Object . defineProperty ( objWithNonEnum , '__path__' , {
2859+ value : 'non-enum-prop' ,
2860+ enumerable : false ,
2861+ } ) ;
2862+ expect ( stripNonEnumerable ( objWithNonEnum ) ) . toStrictEqual ( { a : 1 , b : 2 , c : 3 } ) ;
2863+ } ) ;
2864+
2865+ test ( 'works correctly for null' , ( ) => {
2866+ expect ( stripNonEnumerable ( null ) ) . toStrictEqual ( null ) ;
2867+ } ) ;
2868+
2869+ test ( 'works correctly for undefined' , ( ) => {
2870+ expect ( stripNonEnumerable ( undefined ) ) . toStrictEqual ( undefined ) ;
2871+ } ) ;
2872+
2873+ test ( 'works correctly for string' , ( ) => {
2874+ expect ( stripNonEnumerable ( 'string' ) ) . toStrictEqual ( 'string' ) ;
2875+ } ) ;
2876+
2877+ test ( 'works correctly for number' , ( ) => {
2878+ expect ( stripNonEnumerable ( 1 ) ) . toStrictEqual ( 1 ) ;
2879+ } ) ;
2880+
2881+ test ( 'works correctly for boolean' , ( ) => {
2882+ expect ( stripNonEnumerable ( true ) ) . toStrictEqual ( true ) ;
2883+ } ) ;
2884+ } ) ;
0 commit comments