-
-
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: implement useStrictShallowCopy
- Loading branch information
hrsh7th
committed
May 18, 2022
1 parent
d30d219
commit b3f10f2
Showing
8 changed files
with
105 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import produce, {enableAllPlugins, setUseStrictShallowCopy} from "../src/immer" | ||
|
||
enableAllPlugins() | ||
|
||
describe("setUseStrictShallowCopy(true)", () => { | ||
test("keep property", () => { | ||
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("keep property", () => { | ||
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