frozen.js
This file
Path
__tests__/frozen.js
58 lines · 1.9 KiB · JavaScript
Last changed by
Renamed `index.js` -> `immer.js`Michel Weststratebefore adoptionc4f5667
History of this fileTake it
Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 1why, one step back1"use strict"Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 2why, one step back2import deepFreeze from "deep-freeze"Renamed `index.js` -> `immer.js`Michel Weststratebefore adoptionc4f5667
line 3why, one step back3import produce, {setUseProxies, setAutoFreeze} from "../src/immer"Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 4why, one step back4Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
lines 5–6why, one step back5runTests("proxy", true)6runTests("es5", false)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 7why, one step back7Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
line 8why, one step back8function runTests(name, useProxies) {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 9why, one step back9 describe("auto freeze - " + name, () => {Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
line 10why, one step back10 setUseProxies(useProxies)Fixed broken test suiteMichel Weststratebefore adoption9e5d647
lines 11–12why, one step back11 setAutoFreeze(true)12Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 13–16why, one step back13 const baseState = {14 object: {a: 1},15 array: [1, 2]16 }Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 17why, one step back17Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 18–19why, one step back18 it("should freeze objects after modifications", () => {19 expect(Object.isFrozen(baseState.object)).toBe(false) // initially not frozen`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 20why, one step back20 const next = produce(baseState, draft => {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 21–25why, one step back21 draft.object.c = 222 })23 expect(Object.isFrozen(next.object)).toBe(true)24 expect(Object.isFrozen(next)).toBe(true)25 expect(Object.isFrozen(next.array)).toBe(false)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 26why, one step back26Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 27–29why, one step back27 expect(() => {28 next.object.a = 229 }).toThrow(/Cannot assign to read only property/)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
lines 30–31why, one step back30 })31Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 32–33why, one step back32 it("should freeze arrays after modifications", () => {33 expect(Object.isFrozen(baseState.object)).toBe(false) // initially not frozen`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 34why, one step back34 const next = produce(baseState, draft => {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 35–39why, one step back35 draft.array.push(3)36 })37 expect(Object.isFrozen(next.object)).toBe(false) // not touched38 expect(Object.isFrozen(next)).toBe(true)39 expect(Object.isFrozen(next.array)).toBe(true)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 40why, one step back40Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 41–43why, one step back41 expect(() => {42 next.array.shift()43 }).toThrow(/Cannot add\/remove sealed array elements/)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 44why, one step back44 })Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 45–50why, one step back4546 it("can handle already frozen trees", () => {47 const a = []48 const b = {a: a}49 Object.freeze(a)50 Object.freeze(b)`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 51why, one step back51 const n = produce(b, draft => {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 52–56why, one step back52 draft.c = true53 draft.a.push(3)54 })55 expect(n).toEqual({c: true, a: [3]})56 })Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 57why, one step back57 })Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 58why, one step back58}