Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than a1f5c6a point at it.

Readme improvementsMichel Weststratebefore adoptiona1f5c6a

lines 1–2why, one step back
1"use strict"
2import deepFreeze from "deep-freeze"

Renamed `index.js` -> `immer.js`Michel Weststratebefore adoptionc4f5667

line 3why, one step back
3import produce, {setUseProxies, setAutoFreeze} from "../src/immer"

Readme improvementsMichel Weststratebefore adoptiona1f5c6a

line 4why, one step back
4

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

lines 5–6why, one step back
5runTests("proxy", true)
6runTests("es5", false)

Readme improvementsMichel Weststratebefore adoptiona1f5c6a

line 7why, one step back
7

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

line 8why, one step back
8function runTests(name, useProxies) {

Readme improvementsMichel Weststratebefore adoptiona1f5c6a

line 9why, one step back
9 describe("auto freeze - " + name, () => {

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

line 10why, one step back
10 setUseProxies(useProxies)

Fixed broken test suiteMichel Weststratebefore adoption9e5d647

lines 11–12why, one step back
11 setAutoFreeze(true)
12

Readme improvementsMichel Weststratebefore adoptiona1f5c6a

lines 13–19why, one step back
13 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 back
20 const next = produce(baseState, draft => {

Readme improvementsMichel Weststratebefore adoptiona1f5c6a

lines 21–33why, one step back
21 draft.object.c = 2
22 })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 back
34 const next = produce(baseState, draft => {

Readme improvementsMichel Weststratebefore adoptiona1f5c6a

lines 35–42why, one step back
35 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 back
43 }).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 back
47 })
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 back
54 const n = produce(b, draft => {

Readme improvementsMichel Weststratebefore adoptiona1f5c6a

lines 55–61why, one step back
55 draft.c = true
56 draft.a.push(3)57 })58 expect(n).toEqual({c: true, a: [3]})59 })60 })61}