File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
packages/expect-utils/src Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -591,6 +591,36 @@ describe('iterableEquality', () => {
591591 const b = new TestRecord ( ) . set ( 'dummy' , 'data' ) ;
592592 expect ( iterableEquality ( a , b ) ) . toBe ( true ) ;
593593 } ) ;
594+
595+ test ( 'returns true when given a symbols keys within equal objects' , ( ) => {
596+ const KEY = Symbol ( )
597+
598+ const a = {
599+ [ Symbol . iterator ] : ( ) => ( { next : ( ) => ( { done : true } ) } ) ,
600+ [ KEY ] : [ ] ,
601+ } ;
602+ const b = {
603+ [ Symbol . iterator ] : ( ) => ( { next : ( ) => ( { done : true } ) } ) ,
604+ [ KEY ] : [ ] ,
605+ } ;
606+
607+ expect ( iterableEquality ( a , b ) ) . toBe ( true ) ;
608+ } ) ;
609+
610+ test ( 'returns false when given a symbols keys within inequal objects' , ( ) => {
611+ const KEY = Symbol ( )
612+
613+ const a = {
614+ [ Symbol . iterator ] : ( ) => ( { next : ( ) => ( { done : true } ) } ) ,
615+ [ KEY ] : [ 1 ] ,
616+ } ;
617+ const b = {
618+ [ Symbol . iterator ] : ( ) => ( { next : ( ) => ( { done : true } ) } ) ,
619+ [ KEY ] : [ ] ,
620+ } ;
621+
622+ expect ( iterableEquality ( a , b ) ) . toBe ( false ) ;
623+ } ) ;
594624} ) ;
595625
596626describe ( 'typeEquality' , ( ) => {
Original file line number Diff line number Diff line change @@ -307,8 +307,8 @@ export const iterableEquality = (
307307 ! isImmutableOrderedSet ( a ) &&
308308 ! isImmutableRecord ( a )
309309 ) {
310- const aEntries = Object . entries ( a ) ;
311- const bEntries = Object . entries ( b ) ;
310+ const aEntries = entries ( a ) ;
311+ const bEntries = entries ( b ) ;
312312 if ( ! equals ( aEntries , bEntries ) ) {
313313 return false ;
314314 }
@@ -320,6 +320,17 @@ export const iterableEquality = (
320320 return true ;
321321} ;
322322
323+ const entries = ( obj : any ) => {
324+ if ( ! isObject ( obj ) ) return [ ] ;
325+
326+ return Object
327+ . getOwnPropertySymbols ( obj )
328+ . filter ( key => key !== Symbol . iterator )
329+ . map ( key => [ key , obj [ key ] ] )
330+
331+ . concat ( Object . entries ( obj ) )
332+ }
333+
323334const isObject = ( a : any ) => a !== null && typeof a === 'object' ;
324335
325336const isObjectWithKeys = ( a : any ) =>
You can’t perform that action at this time.
0 commit comments