@@ -10,125 +10,118 @@ describe('partitionObjectArray', () => {
10
10
it ( 'should extract multiple properties from array of objects' , ( ) => {
11
11
const items = [
12
12
{ id : 1 , name : 'John' , age : 25 , city : 'NY' } ,
13
- { id : 2 , name : 'Jane' , age : 30 , city : 'LA' }
13
+ { id : 2 , name : 'Jane' , age : 30 , city : 'LA' } ,
14
14
] ;
15
15
const result = partitionObjectArray ( items , [ 'id' , 'name' ] ) ;
16
16
expect ( result ) . to . deep . equal ( {
17
17
id : [ 1 , 2 ] ,
18
18
name : [ 'John' , 'Jane' ] ,
19
19
rest : [
20
20
{ age : 25 , city : 'NY' } ,
21
- { age : 30 , city : 'LA' }
22
- ]
21
+ { age : 30 , city : 'LA' } ,
22
+ ] ,
23
23
} ) ;
24
24
} ) ;
25
25
26
26
it ( 'should handle objects with missing properties' , ( ) => {
27
27
const items = [
28
28
{ id : 1 , name : 'John' , age : 25 } ,
29
29
{ id : 2 , age : 30 } ,
30
- { id : 3 , name : 'Bob' , city : 'LA' }
30
+ { id : 3 , name : 'Bob' , city : 'LA' } ,
31
31
] ;
32
32
const result = partitionObjectArray ( items , [ 'id' , 'name' ] ) ;
33
33
expect ( result ) . to . deep . equal ( {
34
34
id : [ 1 , 2 , 3 ] ,
35
35
name : [ 'John' , undefined , 'Bob' ] ,
36
- rest : [
37
- { age : 25 } ,
38
- { age : 30 } ,
39
- { city : 'LA' }
40
- ]
36
+ rest : [ { age : 25 } , { age : 30 } , { city : 'LA' } ] ,
41
37
} ) ;
42
38
} ) ;
43
39
44
40
it ( 'should handle different value types' , ( ) => {
45
41
const items = [
46
42
{ id : 1 , active : true , count : 10 , tags : [ 'a' , 'b' ] } ,
47
- { id : 2 , active : false , count : 20 , tags : [ 'c' ] }
43
+ { id : 2 , active : false , count : 20 , tags : [ 'c' ] } ,
48
44
] ;
49
45
const result = partitionObjectArray ( items , [ 'active' , 'tags' ] ) ;
50
46
expect ( result ) . to . deep . equal ( {
51
47
active : [ true , false ] ,
52
48
tags : [ [ 'a' , 'b' ] , [ 'c' ] ] ,
53
49
rest : [
54
50
{ id : 1 , count : 10 } ,
55
- { id : 2 , count : 20 }
56
- ]
51
+ { id : 2 , count : 20 } ,
52
+ ] ,
57
53
} ) ;
58
54
} ) ;
59
55
60
56
it ( 'should handle extracting all properties (empty rest)' , ( ) => {
61
57
const items = [
62
58
{ id : 1 , name : 'John' } ,
63
- { id : 2 , name : 'Jane' }
59
+ { id : 2 , name : 'Jane' } ,
64
60
] ;
65
61
const result = partitionObjectArray ( items , [ 'id' , 'name' ] ) ;
66
62
expect ( result ) . to . deep . equal ( {
67
63
id : [ 1 , 2 ] ,
68
64
name : [ 'John' , 'Jane' ] ,
69
- rest : [ { } , { } ]
65
+ rest : [ { } , { } ] ,
70
66
} ) ;
71
67
} ) ;
72
68
73
69
it ( 'should handle extracting no properties (everything in rest)' , ( ) => {
74
70
const items = [
75
71
{ id : 1 , name : 'John' } ,
76
- { id : 2 , name : 'Jane' }
72
+ { id : 2 , name : 'Jane' } ,
77
73
] ;
78
74
const result = partitionObjectArray ( items , [ ] ) ;
79
75
expect ( result ) . to . deep . equal ( {
80
76
rest : [
81
77
{ id : 1 , name : 'John' } ,
82
- { id : 2 , name : 'Jane' }
83
- ]
78
+ { id : 2 , name : 'Jane' } ,
79
+ ] ,
84
80
} ) ;
85
81
} ) ;
86
82
87
83
it ( 'should handle objects with null or undefined values' , ( ) => {
88
84
const items = [
89
85
{ id : 1 , name : null , age : 25 } ,
90
- { id : 2 , name : undefined , age : 30 }
86
+ { id : 2 , name : undefined , age : 30 } ,
91
87
] ;
92
88
const result = partitionObjectArray ( items , [ 'id' , 'name' ] ) ;
93
89
expect ( result ) . to . deep . equal ( {
94
90
id : [ 1 , 2 ] ,
95
91
name : [ null , undefined ] ,
96
- rest : [
97
- { age : 25 } ,
98
- { age : 30 }
99
- ]
92
+ rest : [ { age : 25 } , { age : 30 } ] ,
100
93
} ) ;
101
94
} ) ;
102
95
103
96
it ( 'should handle nested objects' , ( ) => {
104
97
const items = [
105
98
{ id : 1 , user : { name : 'John' , age : 25 } } ,
106
- { id : 2 , user : { name : 'Jane' , age : 30 } }
99
+ { id : 2 , user : { name : 'Jane' , age : 30 } } ,
107
100
] ;
108
101
const result = partitionObjectArray ( items , [ 'id' , 'user' ] ) ;
109
102
expect ( result ) . to . deep . equal ( {
110
103
id : [ 1 , 2 ] ,
111
104
user : [
112
105
{ name : 'John' , age : 25 } ,
113
- { name : 'Jane' , age : 30 }
106
+ { name : 'Jane' , age : 30 } ,
114
107
] ,
115
- rest : [ { } , { } ]
108
+ rest : [ { } , { } ] ,
116
109
} ) ;
117
110
} ) ;
118
111
119
112
it ( 'should preserve property order in rest object' , ( ) => {
120
113
const items = [
121
114
{ a : 1 , b : 2 , c : 3 , d : 4 } ,
122
- { a : 5 , b : 6 , c : 7 , d : 8 }
115
+ { a : 5 , b : 6 , c : 7 , d : 8 } ,
123
116
] ;
124
117
const result = partitionObjectArray ( items , [ 'a' , 'c' ] ) ;
125
118
expect ( result ) . to . deep . equal ( {
126
119
a : [ 1 , 5 ] ,
127
120
c : [ 3 , 7 ] ,
128
121
rest : [
129
122
{ b : 2 , d : 4 } ,
130
- { b : 6 , d : 8 }
131
- ]
123
+ { b : 6 , d : 8 } ,
124
+ ] ,
132
125
} ) ;
133
126
} ) ;
134
127
} ) ;
0 commit comments