-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better polyfill implementation for cloning arrays and objects
- Loading branch information
Showing
2 changed files
with
66 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import {polyfillClone} from "../../../src"; | ||
|
||
describe('src/utils/clone', function () { | ||
it('should polyfill clone objects with circular reference', () => { | ||
const foo : Record<string, any> = {bar: 'baz'}; | ||
foo.boz = foo; | ||
|
||
const copy = polyfillClone(foo); | ||
expect(copy).toEqual(foo); | ||
}); | ||
|
||
it('should polyfill clone arrays with circular reference', () => { | ||
const foo : any = ['bar']; | ||
foo.push(foo); | ||
|
||
const copy = polyfillClone(foo); | ||
expect(copy).toEqual(foo); | ||
}) | ||
}); |