@@ -647,61 +647,50 @@ describe('dropUndefinedKeys()', () => {
647647} ) ;
648648
649649describe ( 'objectify()' , ( ) => {
650- it ( 'turns undefined and null into `String` objects' , ( ) => {
651- const objectifiedUndefined = objectify ( undefined ) ;
652- const objectifiedNull = objectify ( null ) ;
650+ describe ( 'stringifies nullish values' , ( ) => {
651+ it . each ( [
652+ [ 'undefined' , undefined ] ,
653+ [ 'null' , null ] ,
654+ ] ) ( '%s' , ( stringifiedValue , origValue ) : void => {
655+ const objectifiedNullish = objectify ( origValue ) ;
653656
654- // not string literals but instances of the class `String`
655- expect ( objectifiedUndefined ) . toEqual ( expect . any ( String ) ) ;
656- expect ( objectifiedNull ) . toEqual ( expect . any ( String ) ) ;
657-
658- expect ( objectifiedUndefined . valueOf ( ) ) . toEqual ( 'undefined' ) ;
659- expect ( objectifiedNull . valueOf ( ) ) . toEqual ( 'null' ) ;
657+ expect ( objectifiedNullish ) . toEqual ( expect . any ( String ) ) ;
658+ expect ( objectifiedNullish . valueOf ( ) ) . toEqual ( stringifiedValue ) ;
659+ } ) ;
660660 } ) ;
661661
662- it ( 'wraps other primitives with their respective object wrapper classes' , ( ) => {
663- // Note: BigInts are tested separately in order to be able to restrict the Node version on which the tests run
664- const numberPrimitive = 1121 ;
665- const stringPrimitive = 'Dogs are great!' ;
666- const booleanPrimitive = true ;
667- const symbolPrimitive = Symbol ( 'Maisey' ) ;
668-
669- const objectifiedNumber = objectify ( numberPrimitive ) ;
670- const objectifiedString = objectify ( stringPrimitive ) ;
671- const objectifiedBoolean = objectify ( booleanPrimitive ) ;
672- const objectifiedSymbol = objectify ( symbolPrimitive ) ;
673-
674- // not literals but instances of the respective wrapper classes
675- expect ( objectifiedNumber ) . toEqual ( expect . any ( Number ) ) ;
676- expect ( objectifiedString ) . toEqual ( expect . any ( String ) ) ;
677-
662+ describe ( 'wraps other primitives with their respective object wrapper classes' , ( ) => {
678663 // TODO: There's currently a bug in Jest - if you give it the `Boolean` class, it runs `typeof received ===
679664 // 'boolean'` but not `received instanceof Boolean` (the way it correctly does for other primitive wrappers, like
680665 // `Number` and `String). (See https://github.com/facebook/jest/pull/11976.) Once that is fixed and we upgrade jest,
681666 // we can comment the test below back in. (The tests for symbols and bigints are working only because our current
682667 // version of jest is sufficiently old that they're not even considered in the relevant check and just fall to the
683668 // default `instanceof` check jest uses for all unknown classes.)
684669
685- // expect(objectifiedBoolean).toEqual(expect.any(Boolean));
686- expect ( objectifiedSymbol ) . toEqual ( expect . any ( Symbol ) ) ;
670+ it . each ( [
671+ [ 'number' , Number , 1121 ] ,
672+ [ 'string' , String , 'Dogs are great!' ] ,
673+ // ["boolean", Boolean, true],
674+ [ 'symbol' , Symbol , Symbol ( 'Maisey' ) ] ,
675+ ] ) ( '%s' , ( _caseName , wrapperClass , primitive ) => {
676+ const objectifiedPrimitive = objectify ( primitive ) ;
687677
688- expect ( objectifiedNumber . valueOf ( ) ) . toEqual ( numberPrimitive ) ;
689- expect ( objectifiedString . valueOf ( ) ) . toEqual ( stringPrimitive ) ;
690- expect ( objectifiedBoolean . valueOf ( ) ) . toEqual ( booleanPrimitive ) ;
691- expect ( objectifiedSymbol . valueOf ( ) ) . toEqual ( symbolPrimitive ) ;
692- } ) ;
678+ expect ( objectifiedPrimitive ) . toEqual ( expect . any ( wrapperClass ) ) ;
679+ expect ( objectifiedPrimitive . valueOf ( ) ) . toEqual ( primitive ) ;
680+ } ) ;
693681
694- // `BigInt` doesn't exist in Node < 10.
695- testOnlyIfNodeVersionAtLeast ( 10 ) ( 'wraps bigints with the `BigInt` class ' , ( ) => {
696- // Hack to get around the fact that literal bigints cause a syntax error in older versions of Node, so the
697- // assignment needs to not even be parsed as code in those versions
698- let bigintPrimitive ;
699- eval ( 'bigintPrimitive = 1231n;' ) ;
682+ // `BigInt` doesn't exist in Node < 10, so we test it separately here .
683+ testOnlyIfNodeVersionAtLeast ( 10 ) ( 'bigint ' , ( ) => {
684+ // Hack to get around the fact that literal bigints cause a syntax error in older versions of Node, so the
685+ // assignment needs to not even be parsed as code in those versions
686+ let bigintPrimitive ;
687+ eval ( 'bigintPrimitive = 1231n;' ) ;
700688
701- const objectifiedBigInt = objectify ( bigintPrimitive ) ;
689+ const objectifiedBigInt = objectify ( bigintPrimitive ) ;
702690
703- expect ( objectifiedBigInt ) . toEqual ( expect . any ( BigInt ) ) ;
704- expect ( objectifiedBigInt . valueOf ( ) ) . toEqual ( bigintPrimitive ) ;
691+ expect ( objectifiedBigInt ) . toEqual ( expect . any ( BigInt ) ) ;
692+ expect ( objectifiedBigInt . valueOf ( ) ) . toEqual ( bigintPrimitive ) ;
693+ } ) ;
705694 } ) ;
706695
707696 it ( 'leaves objects alone' , ( ) => {
0 commit comments