-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support symbol properties * fix type to support all peoperty keys
- Loading branch information
1 parent
9dcca68
commit 5308602
Showing
2 changed files
with
39 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ type User = { | |
emails: string[]; | ||
toString: string; | ||
constructor: string | null; | ||
[Symbol.isConcatSpreadable]: boolean; | ||
}; | ||
|
||
describe("defaultComposer", () => { | ||
|
@@ -38,6 +39,7 @@ describe("defaultComposer", () => { | |
emails: ["[email protected]"], | ||
hobbies: ["programming"], | ||
toString: "I am Aral", | ||
[Symbol.isConcatSpreadable]: false, | ||
}; | ||
|
||
const originalObject = { | ||
|
@@ -70,6 +72,7 @@ describe("defaultComposer", () => { | |
hobbies: ["parkour", "computer science", "books", "nature"], | ||
toString: "I am Aral", | ||
constructor: null, | ||
[Symbol.isConcatSpreadable]: false, | ||
}; | ||
|
||
expect(defaultComposer<User>(defaults, originalObject)).toEqual(expected); | ||
|
@@ -137,6 +140,30 @@ describe("defaultComposer", () => { | |
expect(mockFn).toBeCalledTimes(1); | ||
}); | ||
|
||
it("should work with enumerable symbol properties", () => { | ||
const tag = Symbol.for("tag"); | ||
const version = Symbol.for("version"); | ||
const createdAt = Symbol.for("createdAt"); | ||
|
||
const defaults = { | ||
[tag]: "user", | ||
[createdAt]: Date.UTC(2020, 1, 1), | ||
}; | ||
|
||
Object.defineProperty(defaults, version, { value: 1, enumerable: false }); | ||
|
||
const object = { | ||
[createdAt]: Date.UTC(2023, 6, 1), | ||
}; | ||
|
||
const expected = { | ||
[tag]: "user", | ||
[createdAt]: Date.UTC(2023, 6, 1), | ||
}; | ||
|
||
expect(defaultComposer<any>(defaults, object)).toEqual(expected); | ||
}); | ||
|
||
it("should work with a custom isDefaultableValue", () => { | ||
const defaults = { | ||
original: { | ||
|
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