-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: update compare method. add checkDeepValue
- Loading branch information
Showing
11 changed files
with
374 additions
and
47 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
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,5 @@ | ||
import checkPrimitiveValue from "./check-primitive-value"; | ||
|
||
export default function checkDeepValue(value: unknown) { | ||
return !checkPrimitiveValue(value) && !Array.isArray(value) && !Object.isFrozen(value); | ||
} |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
/** | ||
* @deprecated | ||
* */ | ||
export default (v: any) => v === null || v === undefined || Array.isArray(v) || typeof v !== 'object'; |
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
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 |
---|---|---|
@@ -1,19 +1,9 @@ | ||
import checkPrimitiveType from "./check-primitive-type"; | ||
import checkDeepValue from "./check-deep-value"; | ||
|
||
/** | ||
* @description Method using for check for value is endpoint? | ||
* @return {Boolean} If provided object is primitive or frozen return true, otherwise return false. | ||
*/ | ||
export default function isEndPointValue(v: any) { | ||
|
||
if (checkPrimitiveType(v)) return true; | ||
|
||
/** | ||
* If value of frozen, For example, in case passing File or some Class Data. | ||
*/ | ||
if ( | ||
Object.isFrozen(v) | ||
) return true; | ||
|
||
return false; | ||
return !checkDeepValue(v); | ||
} |
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,23 @@ | ||
import checkDeepValue from "./../../src/utils/check-deep-value"; | ||
|
||
describe("Check deep value", () => { | ||
test("Array is not deep value", () => { | ||
expect(checkDeepValue([1,2])).toBe(false) | ||
}) | ||
test("Frozen object is not deep value", () => { | ||
const data = Object.freeze({a: 1}) | ||
expect(checkDeepValue(data)).toBe(false) | ||
}) | ||
test("Primitive is not deep value", () => { | ||
expect(checkDeepValue(1)).toBe(false) | ||
expect(checkDeepValue("1")).toBe(false) | ||
expect(checkDeepValue(null)).toBe(false) | ||
expect(checkDeepValue(undefined)).toBe(false) | ||
expect(checkDeepValue(true)).toBe(false) | ||
}) | ||
test("Object is deep value", () => { | ||
expect(checkDeepValue({ | ||
name: "Jenesius" | ||
})).toBe(true) | ||
}) | ||
}) |
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,37 @@ | ||
import CompareEvent from "./../../src/classes/CompareEvent"; | ||
|
||
describe("Compare Event", () => { | ||
test("Should restore fields that bind with address", () => { | ||
const newValue = { | ||
address: { | ||
city: "Mogilev" | ||
}, | ||
name: "Jenesius", | ||
age: 24 | ||
} | ||
const event = new CompareEvent(newValue, {}); | ||
const addressEvent = CompareEvent.restoreByName(event, 'address'); | ||
|
||
expect(addressEvent.comparison).toEqual([ | ||
{ | ||
name: '', newValue: { city: "Mogilev" }, oldValue: undefined | ||
}, | ||
{ | ||
name: "city", newValue: "Mogilev", oldValue: undefined | ||
} | ||
]) | ||
}) | ||
test("Should restore fields that bind with address", () => { | ||
const newValue = { | ||
address: { | ||
city: "Mogilev" | ||
}, | ||
name: "Jenesius", | ||
age: 24 | ||
} | ||
const event = new CompareEvent(newValue, {}); | ||
const addressEvent = CompareEvent.restoreByName(event, 'coordinate'); | ||
|
||
expect(addressEvent.comparison).toEqual([]) | ||
}) | ||
}) |
Oops, something went wrong.