-
-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce strictShallowCopy, See #941, hrsh7th-use-strict-shall…
…ow-copy
- Loading branch information
1 parent
d533f24
commit e71aebd
Showing
14 changed files
with
859 additions
and
148 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,37 @@ | ||
import {produce, setUseStrictShallowCopy} from "../src/immer" | ||
|
||
describe("setUseStrictShallowCopy(true)", () => { | ||
test("keep descriptors", () => { | ||
setUseStrictShallowCopy(true) | ||
|
||
const base: Record<string, unknown> = {} | ||
Object.defineProperty(base, "foo", { | ||
value: "foo", | ||
writable: false, | ||
configurable: false | ||
}) | ||
const copy = produce(base, (draft: any) => { | ||
draft.bar = "bar" | ||
}) | ||
expect(Object.getOwnPropertyDescriptor(copy, "foo")).toStrictEqual( | ||
Object.getOwnPropertyDescriptor(base, "foo") | ||
) | ||
}) | ||
}) | ||
|
||
describe("setUseStrictShallowCopy(false)", () => { | ||
test("ignore descriptors", () => { | ||
setUseStrictShallowCopy(false) | ||
|
||
const base: Record<string, unknown> = {} | ||
Object.defineProperty(base, "foo", { | ||
value: "foo", | ||
writable: false, | ||
configurable: false | ||
}) | ||
const copy = produce(base, (draft: any) => { | ||
draft.bar = "bar" | ||
}) | ||
expect(Object.getOwnPropertyDescriptor(copy, "foo")).toBeUndefined() | ||
}) | ||
}) |
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
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
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