Skip to content
Myr

curry.js

This file

Path

__tests__/curry.js

104 lines · 2.4 KiB · JavaScript

Last changed by

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

History of this file

Take it

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

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

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

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

lines 2–8why, one step back
2import produce, {
3 setUseProxies,4 produceWithPatches,5 enableAllPlugins6} from "../src/immer"78enableAllPlugins()

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

lines 9–13why, one step back
9
10runTests("proxy", true)11runTests("es5", false)1213function runTests(name, useProxies) {

style: use tabsuse-tabsbefore adoptiona9c0fd0

line 14why, one step back
14 describe("curry - " + name, () => {

fix: Merge branch 'oriSomething-fix-472'Michel Weststratebefore adoption7a8e4e4

lines 15–17why, one step back
15 beforeAll(() => {
16 setUseProxies(useProxies)17 })

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 18why, one step back
18

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 19–24why, one step back
19 it("should check arguments", () => {
20 expect(() => produce()).toThrowErrorMatchingSnapshot()21 expect(() => produce({})).toThrowErrorMatchingSnapshot()22 expect(() => produce({}, {})).toThrowErrorMatchingSnapshot()23 expect(() => produce({}, () => {}, [])).toThrowErrorMatchingSnapshot()24 })

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 25why, one step back
25

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 26–30why, one step back
26 it("should support currying", () => {
27 const state = [{}, {}, {}]28 const mapper = produce((item, index) => {29 item.index = index30 })

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 31why, one step back
31

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 32–35why, one step back
32 expect(state.map(mapper)).not.toBe(state)
33 expect(state.map(mapper)).toEqual([{index: 0}, {index: 1}, {index: 2}])34 expect(state).toEqual([{}, {}, {}])35 })

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 36why, one step back
36

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 37–43why, one step back
37 it("should support returning new states from curring", () => {
38 const reducer = produce((item, index) => {39 if (!item) {40 return {hello: "world"}41 }42 item.index = index43 })

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 44why, one step back
44

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 45–47why, one step back
45 expect(reducer(undefined, 3)).toEqual({hello: "world"})
46 expect(reducer({}, 3)).toEqual({index: 3})47 })

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 48why, one step back
48

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 49–55why, one step back
49 it("should support passing an initial state as second argument", () => {
50 const reducer = produce(51 (item, index) => {52 item.index = index53 },54 {hello: "world"}55 )

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 56why, one step back
56

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 57–60why, one step back
57 expect(reducer(undefined, 3)).toEqual({hello: "world", index: 3})
58 expect(reducer({}, 3)).toEqual({index: 3})59 expect(reducer()).toEqual({hello: "world", index: undefined})60 })

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 61why, one step back
61

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 62–63why, one step back
62 it("can has fun with change detection", () => {
63 const spread = produce(Object.assign)

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 64why, one step back
64

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 65–68why, one step back
65 const base = {
66 x: 1,67 y: 168 }

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 69why, one step back
69

style: use tabsuse-tabsbefore adoptiona9c0fd0

lines 70–78why, one step back
70 expect({...base}).not.toBe(base)
71 expect(spread(base, {})).toBe(base)72 expect(spread(base, {y: 1})).toBe(base)73 expect(spread(base, {...base})).toBe(base)74 expect(spread(base, {...base, y: 2})).not.toBe(base)75 expect(spread(base, {...base, y: 2})).toEqual({x: 1, y: 2})76 expect(spread(base, {z: 3})).toEqual({x: 1, y: 1, z: 3})77 expect(spread(base, {y: 1})).toBe(base)78 })

Merge pull request #402 from immerjs/produce-with-patchesMichel Weststratebefore adoptiona16deda

lines 79–102why, one step back
79 })
8081 it("support currying for produceWithPatches", () => {82 const increment = produceWithPatches((draft, delta) => {83 draft.x += delta84 })8586 expect(increment({x: 5}, 2)).toEqual([87 {x: 7},88 [89 {90 op: "replace",91 path: ["x"],92 value: 793 }94 ],95 [96 {97 op: "replace",98 path: ["x"],99 value: 5100 }101 ]102 ])

style: use tabsuse-tabsbefore adoptiona9c0fd0

line 103why, one step back
103 })

test: improve "nested producer" testsaleclarsonbefore adoptionf9cd736

line 104why, one step back
104}