updated tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by Michel Weststrate · parent f2a79c7 · Browse files · 1 file·+44 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+44 added−39 removed
- tests:+44 added−39 removed
Provenance
- Commit
8aa4da3- Tree
cc4054a- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Michel Weststrate <mweststrate@gmail.com>- Parent
f2a79c7
1 file changed+44 added−39 removed
modified:__tests__/frozen.js+44 added-39 removed
48 unmodified lines49505152535355565758596061626364656667686970717273747576777879808182835485555657885859606162636465959697666768697071727310374757677107787980818283841138586878889118909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291309 unmodified lines48 unmodified lines expect(next).not.toBe(base) expect(isFrozen(next)).toBeTruthy() expect(isFrozen(next.a)).toBeTruthy() }) })
describe("the result is never auto-frozen when", () => { it("the producer is a no-op", () => { const base = {} const next = produce(base, () => {}) expect(next).toBe(base) expect(isFrozen(next)).toBeFalsy() })
it("the root draft is returned", () => { const base = {} const next = produce(base, draft => draft) expect(next).toBe(base) expect(isFrozen(next)).toBeFalsy() })
it("a nested draft is returned", () => { const base = {a: {}} const next = produce(base, draft => draft.a) expect(next).toBe(base.a) expect(isFrozen(next)).toBeFalsy() })
it("the base state is returned", () => { const base = {} const next = produce(base, () => base) expect(next).toBe(base) expect(isFrozen(next)).toBeFalsy() })
it("a new object replaces a primitive base", () => { const obj = {} const obj = {a: {}} const next = produce(null, () => obj) expect(next).toBe(obj) expect(isFrozen(next)).toBeFalsy() expect(isFrozen(next)).toBeTruthy() expect(isFrozen(next.a)).toBeTruthy() })
it("a new object replaces the entire draft", () => { const obj = {a: {b: {}}} const next = produce({}, () => obj) expect(next).toBe(obj) expect(isFrozen(next)).toBeFalsy() expect(isFrozen(next.a)).toBeFalsy() expect(isFrozen(next.a.b)).toBeFalsy() expect(isFrozen(next)).toBeTruthy() expect(isFrozen(next.a)).toBeTruthy() expect(isFrozen(next.a.b)).toBeTruthy() })
it("a new object is added to the root draft", () => { const base = {} const next = produce(base, draft => { draft.a = {} draft.a = {b: []} }) expect(next).not.toBe(base) expect(isFrozen(next)).toBeTruthy() expect(isFrozen(next.a)).toBeFalsy() expect(isFrozen(next.a)).toBeTruthy() expect(isFrozen(next.b)).toBeTruthy() })
it("a new object is added to a nested draft", () => { const base = {a: {}} const next = produce(base, draft => { draft.a.b = {} draft.a.b = {c: {}} }) expect(next).not.toBe(base) expect(isFrozen(next)).toBeTruthy() expect(isFrozen(next.a)).toBeTruthy() expect(isFrozen(next.a.b)).toBeFalsy() expect(isFrozen(next.a.b)).toBeTruthy() expect(isFrozen(next.a.b.c)).toBeTruthy() }) })
describe("the result is never auto-frozen when", () => { it("the producer is a no-op", () => { const base = {a: {}} const next = produce(base, () => {}) expect(next).toBe(base) expect(isFrozen(next)).toBeFalsy() expect(isFrozen(next.a)).toBeFalsy() })
it("the root draft is returned", () => { const base = {a: {}} const next = produce(base, draft => draft) expect(next).toBe(base) expect(isFrozen(next)).toBeFalsy() expect(isFrozen(next.a)).toBeFalsy() })
it("a nested draft is returned", () => { const base = {a: {}} const next = produce(base, draft => draft.a) expect(next).toBe(base.a) expect(isFrozen(next)).toBeFalsy() })
it("the base state is returned", () => { const base = {} const next = produce(base, () => base) expect(next).toBe(base) expect(isFrozen(next)).toBeFalsy() }) })
it("can handle already frozen trees", () => { const a = [] const b = {a: a} Object.freeze(a)9 unmodified lines