Skip to content

Commit

Permalink
Merge pull request #3 from jfet97/bug-fixing
Browse files Browse the repository at this point in the history
Bug fixing
  • Loading branch information
jfet97 committed Jan 8, 2019
2 parents 4d57c20 + e536c4a commit 2ad1ea0
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ Error objects props will produce a `TypeError` if the `discardErrorObjects` is s
Promise, WeakMap and WeakSet objects will be returned if passed to `omniclone` as sources.\
Promise, WeakMap and WeakSet objects props will be copied by reference.

Map objects will be deeply cloned following same rules of normal objects.\
Set objects will be deeply cloned following same rules of normal objects.
Map objects will be deeply cloned following same rules of normal objects, apart for the object keys that will be always cloned.\
Set objects will be deeply cloned following same rules of normal objects, apart for the object entries that will be always cloned.

## what about the 6th strength?

Expand Down
64 changes: 56 additions & 8 deletions __test__/omniclone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("omniclone", () => {
enumerable: false,
value: 42
});
testObj.symbol = Symbol("symbol");
testObj[Symbol("symbol")] = "value";
Object.defineProperty(testObj, "g&s", {
get: () => 42,
set: () => {}
Expand All @@ -40,7 +40,7 @@ describe("omniclone", () => {
expect(res.constructor).toBe(Test);
expect(Object.getPrototypeOf(res)).toBe(Test.prototype);
expect(res.notEnum).toBeUndefined();
expect(res.symbol).toBeUndefined();
expect(res[Symbol("symbol")]).toBeUndefined();
expect(res["g&s"]).toBeUndefined();
})();

Expand Down Expand Up @@ -478,25 +478,25 @@ describe("omniclone", () => {
it("should not copy symbols if the copySymbols flag is set to false", () => {
(() => {
const obj = {};
obj.s = Symbol("s");
obj[Symbol("s")] = "s";
const res = omniclone(obj);
expect(res.s).toBeUndefined();
expect(res[Symbol("s")]).toBeUndefined();
})();

(() => {
const obj = {};
obj.s = Symbol("s");
obj[Symbol("s")] = "s";
const res = omniclone(obj, { copySymbols: false });
expect(res.s).toBeUndefined();
expect(res[Symbol("s")]).toBeUndefined();
})();
});

it("should shallow copy symbols if the copySymbols flag is set to true", () => {
(() => {
const obj = {};
obj.s = Symbol("s");
obj[Symbol("s")] = "s";
const res = omniclone(obj, { copySymbols: true });
expect(res.s).toBe(obj.s);
expect(res[Symbol("s")]).toBe(obj[Symbol("s")]);
})();
});

Expand Down Expand Up @@ -1569,4 +1569,52 @@ describe("omniclone", () => {
expect(resSetObj2 === res).toBe(true);
})();
});

it("should not throw a TypeError because there are not circ references", () => {
(() => {
const ob0 = {};
const ob1 = {};
const ob2 = {};
const ob3 = {};

ob0.ob1 = ob1;
ob0.ob2 = ob2;

ob1.ob3 = ob3;
ob2.ob3 = ob3;
expect(() => {
omniclone(ob0);
}).not.toThrow(TypeError("TypeError: circular reference found"));
})();

(() => {
const ob0 = {};
const ob1 = {};
const ob2 = {};
ob0.ob1 = ob1;
ob0.ob2 = ob2;

ob1.ob2 = ob2;
expect(() => {
omniclone(ob0);
}).not.toThrow(TypeError("TypeError: circular reference found"));
})();

(() => {
const ob0 = {};
const ob1 = {};
const ob2 = {};
const ob3 = {};

ob0.ob1 = ob1;
ob0.ob2 = ob2;

ob2.ob3 = ob3;
ob3.ob1 = ob1;

expect(() => {
omniclone(ob0);
}).not.toThrow(TypeError("TypeError: circular reference found"));
})();
});
});
2 changes: 1 addition & 1 deletion dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omniclone",
"version": "0.5.3",
"version": "0.6.0",
"description": "deep cloning function for js objects",
"main": "dist/main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/otherObjectsDescriptorsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = (
// the copySymbols setted to true indicates that
// we can copy symbol props
// if we mustn't copy symbols and the current prop is a symbol we return
if (!copySymbols && typeof value === "symbol") return;
if (!copySymbols && typeof prop === "symbol") return;

// copyGettersSetters setted to true indicates that
// we can copy getters and setters
Expand Down
Loading

0 comments on commit 2ad1ea0

Please sign in to comment.