Skip to content
Myr

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 file

Take it

Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494

line 1why, one step back
1"use strict"

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

line 2why, one step back
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"

Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494

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)

Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494

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) {

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

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

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 13–16why, one step back
13 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 back
17

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 18–19why, one step back
18 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 => {

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 21–25why, 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)

Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494

line 26why, one step back
26

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 27–29why, one step back
27 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 back
30 })
31

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 32–33why, one step back
32 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 => {

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 35–39why, 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)

Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494

line 40why, one step back
40

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 41–43why, one step back
41 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 back
44 })

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 45–50why, one step back
45
46 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 back
51 const n = produce(b, draft => {

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

lines 52–56why, one step back
52 draft.c = true
53 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 back
57 })

Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957

line 58why, one step back
58}