@@ -23,9 +23,9 @@ it('returns the same value for primitive or function values', () => {
23
23
it ( 'does not execute getters/setters, but copies them' , ( ) => {
24
24
const fn = jest . fn ( ) ;
25
25
const obj = {
26
- // @ts -expect-error
27
26
get foo ( ) {
28
27
fn ( ) ;
28
+ return ;
29
29
} ,
30
30
} ;
31
31
const copy = deepCyclicCopy ( obj ) ;
@@ -49,8 +49,11 @@ it('copies arrays as array objects', () => {
49
49
} ) ;
50
50
51
51
it ( 'handles cyclic dependencies' , ( ) => {
52
- const cyclic : any = { a : 42 , subcycle : { } } ;
52
+ type Cyclic = { [ key : string ] : unknown | Cyclic } & { subcycle ?: Cyclic } ;
53
53
54
+ const cyclic : Cyclic = { a : 42 } ;
55
+
56
+ cyclic . subcycle = { } ;
54
57
cyclic . subcycle . baz = cyclic ;
55
58
cyclic . bar = cyclic ;
56
59
@@ -60,7 +63,7 @@ it('handles cyclic dependencies', () => {
60
63
61
64
expect ( copy . a ) . toBe ( 42 ) ;
62
65
expect ( copy . bar ) . toEqual ( copy ) ;
63
- expect ( copy . subcycle . baz ) . toEqual ( copy ) ;
66
+ expect ( copy . subcycle ? .baz ) . toEqual ( copy ) ;
64
67
} ) ;
65
68
66
69
it ( 'uses the blacklist to avoid copying properties on the first level' , ( ) => {
@@ -84,17 +87,17 @@ it('uses the blacklist to avoid copying properties on the first level', () => {
84
87
} ) ;
85
88
86
89
it ( 'does not keep the prototype by default when top level is object' , ( ) => {
87
- // @ts -expect-error
90
+ // @ts -expect-error: Testing purpose
88
91
const sourceObject = new ( function ( ) { } ) ( ) ;
89
- // @ts -expect-error
92
+ // @ts -expect-error: Testing purpose
90
93
sourceObject . nestedObject = new ( function ( ) { } ) ( ) ;
91
- // @ts -expect-error
94
+ // @ts -expect-error: Testing purpose
92
95
sourceObject . nestedArray = new ( function ( ) {
93
- // @ts -expect-error
96
+ // @ts -expect-error: Testing purpose
94
97
this . length = 0 ;
95
98
} ) ( ) ;
96
99
97
- const spy = jest
100
+ const spyArray = jest
98
101
. spyOn ( Array , 'isArray' )
99
102
. mockImplementation ( object => object === sourceObject . nestedArray ) ;
100
103
@@ -118,15 +121,15 @@ it('does not keep the prototype by default when top level is object', () => {
118
121
Object . getPrototypeOf ( [ ] ) ,
119
122
) ;
120
123
121
- spy . mockRestore ( ) ;
124
+ spyArray . mockRestore ( ) ;
122
125
} ) ;
123
126
124
127
it ( 'does not keep the prototype by default when top level is array' , ( ) => {
125
- const spy = jest . spyOn ( Array , 'isArray' ) . mockImplementation ( ( ) => true ) ;
128
+ const spyArray = jest . spyOn ( Array , 'isArray' ) . mockImplementation ( ( ) => true ) ;
126
129
127
- // @ts -expect-error
130
+ // @ts -expect-error: Testing purpose
128
131
const sourceArray = new ( function ( ) {
129
- // @ts -expect-error
132
+ // @ts -expect-error: Testing purpose
130
133
this . length = 0 ;
131
134
} ) ( ) ;
132
135
@@ -136,15 +139,15 @@ it('does not keep the prototype by default when top level is array', () => {
136
139
) ;
137
140
138
141
expect ( Object . getPrototypeOf ( copy ) ) . toBe ( Object . getPrototypeOf ( [ ] ) ) ;
139
- spy . mockRestore ( ) ;
142
+ spyArray . mockRestore ( ) ;
140
143
} ) ;
141
144
142
145
it ( 'does not keep the prototype of arrays when keepPrototype = false' , ( ) => {
143
- const spy = jest . spyOn ( Array , 'isArray' ) . mockImplementation ( ( ) => true ) ;
146
+ const spyArray = jest . spyOn ( Array , 'isArray' ) . mockImplementation ( ( ) => true ) ;
144
147
145
- // @ts -expect-error
148
+ // @ts -expect-error: Testing purpose
146
149
const sourceArray = new ( function ( ) {
147
- // @ts -expect-error
150
+ // @ts -expect-error: Testing purpose
148
151
this . length = 0 ;
149
152
} ) ( ) ;
150
153
@@ -154,49 +157,49 @@ it('does not keep the prototype of arrays when keepPrototype = false', () => {
154
157
) ;
155
158
156
159
expect ( Object . getPrototypeOf ( copy ) ) . toBe ( Object . getPrototypeOf ( [ ] ) ) ;
157
- spy . mockRestore ( ) ;
160
+ spyArray . mockRestore ( ) ;
158
161
} ) ;
159
162
160
163
it ( 'keeps the prototype of arrays when keepPrototype = true' , ( ) => {
161
- const spy = jest . spyOn ( Array , 'isArray' ) . mockImplementation ( ( ) => true ) ;
164
+ const spyArray = jest . spyOn ( Array , 'isArray' ) . mockImplementation ( ( ) => true ) ;
162
165
163
- // @ts -expect-error
166
+ // @ts -expect-error: Testing purpose
164
167
const sourceArray = new ( function ( ) {
165
- // @ts -expect-error
168
+ // @ts -expect-error: Testing purpose
166
169
this . length = 0 ;
167
170
} ) ( ) ;
168
171
169
172
const copy = deepCyclicCopy ( sourceArray , { keepPrototype : true } ) ;
170
173
expect ( Object . getPrototypeOf ( copy ) ) . toBe ( Object . getPrototypeOf ( sourceArray ) ) ;
171
174
172
- spy . mockRestore ( ) ;
175
+ spyArray . mockRestore ( ) ;
173
176
} ) ;
174
177
175
178
it ( 'does not keep the prototype for objects when keepPrototype = false' , ( ) => {
179
+ // @ts -expect-error: Testing purpose
180
+ const sourceObject = new ( function ( ) { } ) ( ) ;
176
181
// @ts -expect-error
177
- const sourceobject = new ( function ( ) { } ) ( ) ;
178
- // @ts -expect-error
179
- sourceobject . nestedObject = new ( function ( ) { } ) ( ) ;
180
- // @ts -expect-error
181
- sourceobject . nestedArray = new ( function ( ) {
182
- // @ts -expect-error
182
+ sourceObject . nestedObject = new ( function ( ) { } ) ( ) ;
183
+ // @ts -expect-error: Testing purpose
184
+ sourceObject . nestedArray = new ( function ( ) {
185
+ // @ts -expect-error: Testing purpose
183
186
this . length = 0 ;
184
187
} ) ( ) ;
185
188
186
- const spy = jest
189
+ const spyArray = jest
187
190
. spyOn ( Array , 'isArray' )
188
- . mockImplementation ( object => object === sourceobject . nestedArray ) ;
191
+ . mockImplementation ( object => object === sourceObject . nestedArray ) ;
189
192
190
- const copy = deepCyclicCopy ( sourceobject , { keepPrototype : false } ) ;
193
+ const copy = deepCyclicCopy ( sourceObject , { keepPrototype : false } ) ;
191
194
192
195
expect ( Object . getPrototypeOf ( copy ) ) . not . toBe (
193
- Object . getPrototypeOf ( sourceobject ) ,
196
+ Object . getPrototypeOf ( sourceObject ) ,
194
197
) ;
195
198
expect ( Object . getPrototypeOf ( copy . nestedObject ) ) . not . toBe (
196
- Object . getPrototypeOf ( sourceobject . nestedObject ) ,
199
+ Object . getPrototypeOf ( sourceObject . nestedObject ) ,
197
200
) ;
198
201
expect ( Object . getPrototypeOf ( copy . nestedArray ) ) . not . toBe (
199
- Object . getPrototypeOf ( sourceobject . nestedArray ) ,
202
+ Object . getPrototypeOf ( sourceObject . nestedArray ) ,
200
203
) ;
201
204
expect ( Object . getPrototypeOf ( copy ) ) . toBe ( Object . getPrototypeOf ( { } ) ) ;
202
205
expect ( Object . getPrototypeOf ( copy . nestedObject ) ) . toBe (
@@ -206,21 +209,21 @@ it('does not keep the prototype for objects when keepPrototype = false', () => {
206
209
Object . getPrototypeOf ( [ ] ) ,
207
210
) ;
208
211
209
- spy . mockRestore ( ) ;
212
+ spyArray . mockRestore ( ) ;
210
213
} ) ;
211
214
212
215
it ( 'keeps the prototype for objects when keepPrototype = true' , ( ) => {
213
- // @ts -expect-error
216
+ // @ts -expect-error: Testing purpose
214
217
const sourceObject = new ( function ( ) { } ) ( ) ;
215
- // @ts -expect-error
218
+ // @ts -expect-error: Testing purpose
216
219
sourceObject . nestedObject = new ( function ( ) { } ) ( ) ;
217
- // @ts -expect-error
220
+ // @ts -expect-error: Testing purpose
218
221
sourceObject . nestedArray = new ( function ( ) {
219
- // @ts -expect-error
222
+ // @ts -expect-error: Testing purpose
220
223
this . length = 0 ;
221
224
} ) ( ) ;
222
225
223
- const spy = jest
226
+ const spyArray = jest
224
227
. spyOn ( Array , 'isArray' )
225
228
. mockImplementation ( object => object === sourceObject . nestedArray ) ;
226
229
@@ -233,5 +236,5 @@ it('keeps the prototype for objects when keepPrototype = true', () => {
233
236
expect ( Object . getPrototypeOf ( copy . nestedArray ) ) . toBe (
234
237
Object . getPrototypeOf ( sourceObject . nestedArray ) ,
235
238
) ;
236
- spy . mockRestore ( ) ;
239
+ spyArray . mockRestore ( ) ;
237
240
} ) ;
0 commit comments