Skip to content
Myr

original.js

This file

Path

__tests__/original.js

69 lines · 2.2 KiB · JavaScript

Last changed by

chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec

History of this file

Take it

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

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

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

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 2–4why, one step back
2import produce, {original, setUseProxies, enableAllPlugins} from "../src/immer"
34enableAllPlugins()

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 5why, one step back
5

chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec

lines 6–7why, one step back
6const isProd = process.env.NODE_ENV === "production"
7

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 8why, one step back
8describe("original", () => {

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 9–12why, one step back
9 const baseState = {
10 a: [],11 b: {}12 }

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 13why, one step back
13

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 14–15why, one step back
14 it("should return the original from the draft", () => {
15 setUseProxies(true)

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 16why, one step back
16

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 17–21why, one step back
17 produce(baseState, draftState => {
18 expect(original(draftState)).toBe(baseState)19 expect(original(draftState.a)).toBe(baseState.a)20 expect(original(draftState.b)).toBe(baseState.b)21 })

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 22why, one step back
22

style: use tabsuse-tabsbefore adoptiona9c0fd0

line 23why, one step back
23 setUseProxies(false)

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 24why, one step back
24

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 25–30why, one step back
25 produce(baseState, draftState => {
26 expect(original(draftState)).toBe(baseState)27 expect(original(draftState.a)).toBe(baseState.a)28 expect(original(draftState.b)).toBe(baseState.b)29 })30 })

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 31why, one step back
31

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 32–38why, one step back
32 it("should return the original from the proxy", () => {
33 produce(baseState, draftState => {34 expect(original(draftState)).toBe(baseState)35 expect(original(draftState.a)).toBe(baseState.a)36 expect(original(draftState.b)).toBe(baseState.b)37 })38 })

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 39why, one step back
39

Immer 7Michel Weststratebefore adoption467ea5d

line 40why, one step back
40 it("should throw undefined for new values on the draft", () => {

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 41–43why, one step back
41 produce(baseState, draftState => {
42 draftState.c = {}43 draftState.d = 3

Immer 7Michel Weststratebefore adoption467ea5d

line 44why, one step back
44 expect(() => original(draftState.c)).toThrowErrorMatchingInlineSnapshot(

chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec

lines 45–47why, one step back
45 isProd
46 ? `"[Immer] minified error nr: 23 '[object Object]'. Find the full error at: https://bit.ly/3cXEKWf"`47 : `"[Immer] 'original' expects a draft, got: [object Object]"`

Immer 7Michel Weststratebefore adoption467ea5d

lines 48–49why, one step back
48 )
49 expect(() => original(draftState.d)).toThrowErrorMatchingInlineSnapshot(

chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec

lines 50–52why, one step back
50 isProd
51 ? `"[Immer] minified error nr: 23 '3'. Find the full error at: https://bit.ly/3cXEKWf"`52 : `"[Immer] 'original' expects a draft, got: 3"`

Immer 7Michel Weststratebefore adoption467ea5d

line 53why, one step back
53 )

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 54–55why, one step back
54 })
55 })

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 56why, one step back
56

style: use tabsuse-tabsbefore adoptiona9c0fd0

line 57why, one step back
57 it("should return undefined for an object that is not proxied", () => {

Immer 7Michel Weststratebefore adoption467ea5d

line 58why, one step back
58 expect(() => original({})).toThrowErrorMatchingInlineSnapshot(

chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec

lines 59–61why, one step back
59 isProd
60 ? `"[Immer] minified error nr: 23 '[object Object]'. Find the full error at: https://bit.ly/3cXEKWf"`61 : `"[Immer] 'original' expects a draft, got: [object Object]"`

Immer 7Michel Weststratebefore adoption467ea5d

lines 62–63why, one step back
62 )
63 expect(() => original(3)).toThrowErrorMatchingInlineSnapshot(

chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec

lines 64–66why, one step back
64 isProd
65 ? `"[Immer] minified error nr: 23 '3'. Find the full error at: https://bit.ly/3cXEKWf"`66 : `"[Immer] 'original' expects a draft, got: 3"`

Immer 7Michel Weststratebefore adoption467ea5d

line 67why, one step back
67 )

style: use tabsuse-tabsbefore adoptiona9c0fd0

line 68why, one step back
68 })

docs: elaborate on immerable symbolAlec Larsonbefore adoption9e12f56

line 69why, one step back
69})