1+ import defineProperty from '@core-js/pure/es/object/define-property' ;
12import keysLength from '@core-js/pure/full/object/keys-length' ;
3+ import Symbol from '@core-js/pure/es/symbol' ;
24
35QUnit . test ( 'Object.keysLength' , assert => {
46 assert . isFunction ( keysLength ) ;
@@ -9,4 +11,48 @@ QUnit.test('Object.keysLength', assert => {
911 assert . same ( keysLength ( { } ) , 0 , 'Empty object' ) ;
1012 assert . throws ( ( ) => keysLength ( null ) , TypeError ) ;
1113 assert . throws ( ( ) => keysLength ( ) , TypeError ) ;
14+
15+ assert . same ( keysLength ( { a : 1 , [ Symbol ( 's' ) ] : 2 } ) , 1 , 'Ignores symbol keys' ) ;
16+
17+ const nonEnum = { a : 1 } ;
18+ defineProperty ( nonEnum , 'hidden' , {
19+ value : true ,
20+ enumerable : false ,
21+ } ) ;
22+ assert . same ( keysLength ( nonEnum ) , 1 , 'Ignores non-enumerable own properties' ) ;
23+
24+ const withAccessor = { } ;
25+ defineProperty ( withAccessor , 'foo' , {
26+ get ( ) { return 1 ; } ,
27+ enumerable : true ,
28+ } ) ;
29+ assert . same ( keysLength ( withAccessor ) , 1 , 'Counts enumerable accessors' ) ;
30+
31+ const withNonEnumAccessor = { } ;
32+ defineProperty ( withNonEnumAccessor , 'bar' , {
33+ get ( ) { return 1 ; } ,
34+ enumerable : false ,
35+ } ) ;
36+ assert . same ( keysLength ( withNonEnumAccessor ) , 0 , 'Ignores non-enumerable accessors' ) ;
37+
38+ const proto = { a : 1 , b : 2 } ;
39+ const obj = Object . create ( proto ) ;
40+ obj . c = 3 ;
41+ defineProperty ( proto , 'd' , {
42+ value : 4 ,
43+ enumerable : true ,
44+ } ) ;
45+ assert . same ( keysLength ( obj ) , 1 , 'Does not count inherited properties' ) ;
46+
47+ const dict = Object . create ( null ) ;
48+ dict . x = 1 ;
49+ assert . same ( keysLength ( dict ) , 1 , 'Works with null-prototype objects' ) ;
50+
51+ assert . same ( keysLength ( 'abc' ) , 3 , 'String primitive indices are own enumerable keys' ) ;
52+ assert . same ( keysLength ( 42 ) , 0 , 'Number primitive has no enumerable string keys' ) ;
53+ assert . same ( keysLength ( true ) , 0 , 'Boolean primitive has no enumerable string keys' ) ;
54+
55+ const arr = [ 'a' ] ;
56+ arr [ 2 ] = 'b' ;
57+ assert . same ( keysLength ( arr ) , 2 , 'Array counts only present indices' ) ;
1258} ) ;
0 commit comments