Skip to content
Myr

Merge pull request #14 from benbraou/issue10

Before adoption: this commit came in with the history the project adopted, so no landing records it.

invalidate the proxy of the base state after immer function executes

authored by Michel Weststrate · committed by GitHub · parents a151fed, 6a2544d · Browse files · 2 files+56 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+56 added−10 removed

  • tests:+23 added−0 removed
  • other:+33 added−10 removed

2 files+56 added−10 removed

modified:__tests__/base.js+23 added
187 unmodified lines
188 expect(baseState.aProp).toBe("hi")189 expect(nextState.aProp).toBe(undefined)190 })191192 it("should revoke the proxy of the baseState after immer function is executed", () => {193 let proxy194 const nextState = immer(baseState, s => {195 proxy = s196 s.aProp = "hello"197 })198 expect(nextState).not.toBe(baseState)199 expect(baseState.aProp).toBe("hi")200 expect(nextState.aProp).toBe("hello")201202 expect(() => {203 proxy.aProp = "Hallo"204 }).toThrowError(/^Cannot perform.*on a proxy that has been revoked/)205 expect(() => {206 const aProp = proxy.aProp207 }).toThrowError(/^Cannot perform.*on a proxy that has been revoked/) 208209 expect(nextState).not.toBe(baseState)210 expect(baseState.aProp).toBe("hi")211 expect(nextState.aProp).toBe("hello")212213 })214 215 afterEach(() => {216 expect(baseState).toBe(origBaseState)217 expect(baseState).toEqual(createBaseState())218 })
48 unmodified lines
modified:immer.js+33 added-10 removed