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 a1f5c6a point at it.
Readme improvementsMichel Weststratebefore adoptiona1f5c6a
lines 1–2why, one step back1"use strict"2import deepFreeze from "deep-freeze"Renamed `index.js` -> `immer.js`Michel Weststratebefore adoptionc4f5667
line 3why, one step back3import produce, {setUseProxies, setAutoFreeze} from "../src/immer"Readme improvementsMichel Weststratebefore adoptiona1f5c6a
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)Readme improvementsMichel Weststratebefore adoptiona1f5c6a
line 7why, one step back7Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
line 8why, one step back8function runTests(name, useProxies) {Readme improvementsMichel Weststratebefore adoptiona1f5c6a
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)12Readme improvementsMichel Weststratebefore adoptiona1f5c6a
lines 13–19why, one step back13 const baseState = {14 object: {a: 1},15 array: [1, 2]16 }1718 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 => {Readme improvementsMichel Weststratebefore adoptiona1f5c6a
lines 21–33why, 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)2627 expect(() => {28 next.object.a = 229 }).toThrow(/Cannot assign to read only property/)30 })3132 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 => {Readme improvementsMichel Weststratebefore adoptiona1f5c6a
lines 35–42why, 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)4041 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 )Readme improvementsMichel Weststratebefore adoptiona1f5c6a
lines 47–53why, one step back47 })4849 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 => {Readme improvementsMichel Weststratebefore adoptiona1f5c6a
lines 55–61why, one step back55 draft.c = true56 draft.a.push(3)57 })58 expect(n).toEqual({c: true, a: [3]})59 })60 })61}