frozen.js
This file
Path
__tests__/frozen.js
57 lines · 1.9 KiB · JavaScript
Last changed by
transpile es5 codeMichel Weststratebefore adoptionf012154
History of this fileTake it
Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 1why, one step back1"use strict"transpile es5 codeMichel Weststratebefore adoptionf012154
lines 2–3why, one step back2import * as immerProxy from "../src/immer"3import * as immerEs5 from "../src/es5"Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 4why, one step back4import deepFreeze from "deep-freeze"Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 5why, one step back5Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 6–7why, one step back6runTests("proxy", immerProxy)7runTests("es5", immerEs5)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 8why, one step back8Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 9why, one step back9function runTests(name, lib) {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 10why, one step back10 describe("auto freeze - " + name, () => {`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 11why, one step back11 const produce = lib.defaultMerge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 12–15why, one step back12 const baseState = {13 object: {a: 1},14 array: [1, 2]15 }Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 16why, one step back16Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 17–18why, one step back17 it("should freeze objects after modifications", () => {18 expect(Object.isFrozen(baseState.object)).toBe(false) // initially not frozen`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 19why, one step back19 const next = produce(baseState, draft => {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 20–24why, one step back20 draft.object.c = 221 })22 expect(Object.isFrozen(next.object)).toBe(true)23 expect(Object.isFrozen(next)).toBe(true)24 expect(Object.isFrozen(next.array)).toBe(false)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 25why, one step back25Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 26–28why, one step back26 expect(() => {27 next.object.a = 228 }).toThrow(/Cannot assign to read only property/)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
lines 29–30why, one step back29 })30Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 31–32why, one step back31 it("should freeze arrays after modifications", () => {32 expect(Object.isFrozen(baseState.object)).toBe(false) // initially not frozen`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 33why, one step back33 const next = produce(baseState, draft => {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 34–38why, one step back34 draft.array.push(3)35 })36 expect(Object.isFrozen(next.object)).toBe(false) // not touched37 expect(Object.isFrozen(next)).toBe(true)38 expect(Object.isFrozen(next.array)).toBe(true)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 39why, one step back39Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 40–42why, one step back40 expect(() => {41 next.array.shift()42 }).toThrow(/Cannot add\/remove sealed array elements/)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 43why, one step back43 })Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 44–49why, one step back4445 it("can handle already frozen trees", () => {46 const a = []47 const b = {a: a}48 Object.freeze(a)49 Object.freeze(b)`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 50why, one step back50 const n = produce(b, draft => {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 51–55why, one step back51 draft.c = true52 draft.a.push(3)53 })54 expect(n).toEqual({c: true, a: [3]})55 })Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 56why, one step back56 })Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 57why, one step back57}