@@ -23,9 +23,9 @@ it('returns the same value for primitive or function values', () => {
2323it ( 'does not execute getters/setters, but copies them' , ( ) => {
2424 const fn = jest . fn ( ) ;
2525 const obj = {
26- // @ts -expect-error
2726 get foo ( ) {
2827 fn ( ) ;
28+ return ;
2929 } ,
3030 } ;
3131 const copy = deepCyclicCopy ( obj ) ;
@@ -49,8 +49,11 @@ it('copies arrays as array objects', () => {
4949} ) ;
5050
5151it ( 'handles cyclic dependencies' , ( ) => {
52- const cyclic : any = { a : 42 , subcycle : { } } ;
52+ type Cyclic = { [ key : string ] : unknown | Cyclic } & { subcycle ?: Cyclic } ;
5353
54+ const cyclic : Cyclic = { a : 42 } ;
55+
56+ cyclic . subcycle = { } ;
5457 cyclic . subcycle . baz = cyclic ;
5558 cyclic . bar = cyclic ;
5659
@@ -60,7 +63,7 @@ it('handles cyclic dependencies', () => {
6063
6164 expect ( copy . a ) . toBe ( 42 ) ;
6265 expect ( copy . bar ) . toEqual ( copy ) ;
63- expect ( copy . subcycle . baz ) . toEqual ( copy ) ;
66+ expect ( copy . subcycle ? .baz ) . toEqual ( copy ) ;
6467} ) ;
6568
6669it ( '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', () => {
8487} ) ;
8588
8689it ( 'does not keep the prototype by default when top level is object' , ( ) => {
87- // @ts -expect-error
90+ // @ts -expect-error: Testing purpose
8891 const sourceObject = new ( function ( ) { } ) ( ) ;
89- // @ts -expect-error
92+ // @ts -expect-error: Testing purpose
9093 sourceObject . nestedObject = new ( function ( ) { } ) ( ) ;
91- // @ts -expect-error
94+ // @ts -expect-error: Testing purpose
9295 sourceObject . nestedArray = new ( function ( ) {
93- // @ts -expect-error
96+ // @ts -expect-error: Testing purpose
9497 this . length = 0 ;
9598 } ) ( ) ;
9699
97- const spy = jest
100+ const spyArray = jest
98101 . spyOn ( Array , 'isArray' )
99102 . mockImplementation ( object => object === sourceObject . nestedArray ) ;
100103
@@ -118,15 +121,15 @@ it('does not keep the prototype by default when top level is object', () => {
118121 Object . getPrototypeOf ( [ ] ) ,
119122 ) ;
120123
121- spy . mockRestore ( ) ;
124+ spyArray . mockRestore ( ) ;
122125} ) ;
123126
124127it ( '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 ) ;
126129
127- // @ts -expect-error
130+ // @ts -expect-error: Testing purpose
128131 const sourceArray = new ( function ( ) {
129- // @ts -expect-error
132+ // @ts -expect-error: Testing purpose
130133 this . length = 0 ;
131134 } ) ( ) ;
132135
@@ -136,15 +139,15 @@ it('does not keep the prototype by default when top level is array', () => {
136139 ) ;
137140
138141 expect ( Object . getPrototypeOf ( copy ) ) . toBe ( Object . getPrototypeOf ( [ ] ) ) ;
139- spy . mockRestore ( ) ;
142+ spyArray . mockRestore ( ) ;
140143} ) ;
141144
142145it ( '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 ) ;
144147
145- // @ts -expect-error
148+ // @ts -expect-error: Testing purpose
146149 const sourceArray = new ( function ( ) {
147- // @ts -expect-error
150+ // @ts -expect-error: Testing purpose
148151 this . length = 0 ;
149152 } ) ( ) ;
150153
@@ -154,49 +157,49 @@ it('does not keep the prototype of arrays when keepPrototype = false', () => {
154157 ) ;
155158
156159 expect ( Object . getPrototypeOf ( copy ) ) . toBe ( Object . getPrototypeOf ( [ ] ) ) ;
157- spy . mockRestore ( ) ;
160+ spyArray . mockRestore ( ) ;
158161} ) ;
159162
160163it ( '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 ) ;
162165
163- // @ts -expect-error
166+ // @ts -expect-error: Testing purpose
164167 const sourceArray = new ( function ( ) {
165- // @ts -expect-error
168+ // @ts -expect-error: Testing purpose
166169 this . length = 0 ;
167170 } ) ( ) ;
168171
169172 const copy = deepCyclicCopy ( sourceArray , { keepPrototype : true } ) ;
170173 expect ( Object . getPrototypeOf ( copy ) ) . toBe ( Object . getPrototypeOf ( sourceArray ) ) ;
171174
172- spy . mockRestore ( ) ;
175+ spyArray . mockRestore ( ) ;
173176} ) ;
174177
175178it ( 'does not keep the prototype for objects when keepPrototype = false' , ( ) => {
179+ // @ts -expect-error: Testing purpose
180+ const sourceObject = new ( function ( ) { } ) ( ) ;
176181 // @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
183186 this . length = 0 ;
184187 } ) ( ) ;
185188
186- const spy = jest
189+ const spyArray = jest
187190 . spyOn ( Array , 'isArray' )
188- . mockImplementation ( object => object === sourceobject . nestedArray ) ;
191+ . mockImplementation ( object => object === sourceObject . nestedArray ) ;
189192
190- const copy = deepCyclicCopy ( sourceobject , { keepPrototype : false } ) ;
193+ const copy = deepCyclicCopy ( sourceObject , { keepPrototype : false } ) ;
191194
192195 expect ( Object . getPrototypeOf ( copy ) ) . not . toBe (
193- Object . getPrototypeOf ( sourceobject ) ,
196+ Object . getPrototypeOf ( sourceObject ) ,
194197 ) ;
195198 expect ( Object . getPrototypeOf ( copy . nestedObject ) ) . not . toBe (
196- Object . getPrototypeOf ( sourceobject . nestedObject ) ,
199+ Object . getPrototypeOf ( sourceObject . nestedObject ) ,
197200 ) ;
198201 expect ( Object . getPrototypeOf ( copy . nestedArray ) ) . not . toBe (
199- Object . getPrototypeOf ( sourceobject . nestedArray ) ,
202+ Object . getPrototypeOf ( sourceObject . nestedArray ) ,
200203 ) ;
201204 expect ( Object . getPrototypeOf ( copy ) ) . toBe ( Object . getPrototypeOf ( { } ) ) ;
202205 expect ( Object . getPrototypeOf ( copy . nestedObject ) ) . toBe (
@@ -206,21 +209,21 @@ it('does not keep the prototype for objects when keepPrototype = false', () => {
206209 Object . getPrototypeOf ( [ ] ) ,
207210 ) ;
208211
209- spy . mockRestore ( ) ;
212+ spyArray . mockRestore ( ) ;
210213} ) ;
211214
212215it ( 'keeps the prototype for objects when keepPrototype = true' , ( ) => {
213- // @ts -expect-error
216+ // @ts -expect-error: Testing purpose
214217 const sourceObject = new ( function ( ) { } ) ( ) ;
215- // @ts -expect-error
218+ // @ts -expect-error: Testing purpose
216219 sourceObject . nestedObject = new ( function ( ) { } ) ( ) ;
217- // @ts -expect-error
220+ // @ts -expect-error: Testing purpose
218221 sourceObject . nestedArray = new ( function ( ) {
219- // @ts -expect-error
222+ // @ts -expect-error: Testing purpose
220223 this . length = 0 ;
221224 } ) ( ) ;
222225
223- const spy = jest
226+ const spyArray = jest
224227 . spyOn ( Array , 'isArray' )
225228 . mockImplementation ( object => object === sourceObject . nestedArray ) ;
226229
@@ -233,5 +236,5 @@ it('keeps the prototype for objects when keepPrototype = true', () => {
233236 expect ( Object . getPrototypeOf ( copy . nestedArray ) ) . toBe (
234237 Object . getPrototypeOf ( sourceObject . nestedArray ) ,
235238 ) ;
236- spy . mockRestore ( ) ;
239+ spyArray . mockRestore ( ) ;
237240} ) ;
0 commit comments