Skip to content
Myr

original.js

This file

Path

__tests__/original.js

59 lines · 1.7 KiB · JavaScript

Last changed by

Immer 7Michel Weststratebefore adoption467ea5d

History of this file

Take it

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

chore: improve some testsaleclarsonbefore adoptionefd47f6

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

chore: improve some testsaleclarsonbefore adoptionefd47f6

lines 5–6why, one step back
5
6describe("original", () => {

style: use tabsuse-tabsbefore adoptiona9c0fd0

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

chore: improve some testsaleclarsonbefore adoptionefd47f6

line 11why, one step back
11

style: use tabsuse-tabsbefore adoptiona9c0fd0

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

chore: improve some testsaleclarsonbefore adoptionefd47f6

line 14why, one step back
14

style: use tabsuse-tabsbefore adoptiona9c0fd0

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

chore: improve some testsaleclarsonbefore adoptionefd47f6

line 20why, one step back
20

style: use tabsuse-tabsbefore adoptiona9c0fd0

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

chore: improve some testsaleclarsonbefore adoptionefd47f6

line 22why, one step back
22

style: use tabsuse-tabsbefore adoptiona9c0fd0

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

chore: improve some testsaleclarsonbefore adoptionefd47f6

line 29why, one step back
29

style: use tabsuse-tabsbefore adoptiona9c0fd0

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

chore: improve some testsaleclarsonbefore adoptionefd47f6

line 37why, one step back
37

Immer 7Michel Weststratebefore adoption467ea5d

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

style: use tabsuse-tabsbefore adoptiona9c0fd0

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

Immer 7Michel Weststratebefore adoption467ea5d

lines 42–47why, one step back
42 expect(() => original(draftState.c)).toThrowErrorMatchingInlineSnapshot(
43 `"[Immer] 'original' expects a draft, got: [object Object]"`44 )45 expect(() => original(draftState.d)).toThrowErrorMatchingInlineSnapshot(46 `"[Immer] 'original' expects a draft, got: 3"`47 )

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 48–49why, one step back
48 })
49 })

chore: improve some testsaleclarsonbefore adoptionefd47f6

line 50why, one step back
50

style: use tabsuse-tabsbefore adoptiona9c0fd0

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

Immer 7Michel Weststratebefore adoption467ea5d

lines 52–57why, one step back
52 expect(() => original({})).toThrowErrorMatchingInlineSnapshot(
53 `"[Immer] 'original' expects a draft, got: [object Object]"`54 )55 expect(() => original(3)).toThrowErrorMatchingInlineSnapshot(56 `"[Immer] 'original' expects a draft, got: 3"`57 )

style: use tabsuse-tabsbefore adoptiona9c0fd0

line 58why, one step back
58 })

chore: improve some testsaleclarsonbefore adoptionefd47f6

line 59why, one step back
59})