frozen.js
This file
Path
__tests__/frozen.js
61 lines · 2.0 KiB · JavaScript
Last changed by
Merge pull request #199 from stefanwille/fix-tests-for-node-v10.10Michel Weststratebefore adoption0d72d13
History of this fileTake it
The walk stopped after 200 commits: lines older than c8718e7 point at it.
Merge pull request #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
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 #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
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 #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
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 #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
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 #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
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 #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
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 #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
line 40why, one step back40Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 41–42why, one step back41 expect(() => {42 next.array.shift()Merge pull request #199 from stefanwille/fix-tests-for-node-v10.10Michel Weststratebefore adoption0d72d13
lines 43–46why, one step back43 }).toThrow(44 // Exception message for older / newer Node.js version.45 /Cannot add\/remove sealed array elements|Cannot assign to read only property '0' of object '\[object Array\]'/46 )Merge pull request #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
line 47why, one step back47 })Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 48–53why, one step back4849 it("can handle already frozen trees", () => {50 const a = []51 const b = {a: a}52 Object.freeze(a)53 Object.freeze(b)`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 54why, one step back54 const n = produce(b, draft => {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 55–59why, one step back55 draft.c = true56 draft.a.push(3)57 })58 expect(n).toEqual({c: true, a: [3]})59 })Merge pull request #21 from sallyhill/patch-1Michel Weststratebefore adoptionc8718e7
line 60why, one step back60 })Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 61why, one step back61}