curry.js
This file
Path
__tests__/curry.js
78 lines · 2.5 KiB · JavaScript
Last changed by
feat(ts): Improve type inference based on the first arg of the recipe functionMichel Weststratebefore adoptionacf8a57
History of this fileTake it
The walk stopped after 200 commits: lines older than d4a165b point at it.
More readme linksMichel Weststratebefore adoptiond4a165b
line 1why, one step back1"use strict"chore: update import paths in testsaleclarsonbefore adoptioncdc09b1
line 2why, one step back2import produce, {setUseProxies} from "../src/index"More readme linksMichel Weststratebefore adoptiond4a165b
lines 3–11why, one step back34runTests("proxy", true)5runTests("es5", false)67function runTests(name, useProxies) {8 describe("curry - " + name, () => {9 setUseProxies(useProxies)1011 it("should check arguments", () => {test: use Jest snapshots for expected errorsAlec Larsonbefore adoption0ad9a91
lines 12–17why, one step back12 expect(() => produce()).toThrowErrorMatchingSnapshot()13 expect(() => produce({})).toThrowErrorMatchingSnapshot()14 expect(() => produce({}, {})).toThrowErrorMatchingSnapshot()15 expect(() =>16 produce({}, () => {}, [])17 ).toThrowErrorMatchingSnapshot()More readme linksMichel Weststratebefore adoptiond4a165b
lines 18–56why, one step back18 })1920 it("should support currying", () => {21 const state = [{}, {}, {}]22 const mapper = produce((item, index) => {23 item.index = index24 })2526 expect(state.map(mapper)).not.toBe(state)27 expect(state.map(mapper)).toEqual([28 {index: 0},29 {index: 1},30 {index: 2}31 ])32 expect(state).toEqual([{}, {}, {}])33 })3435 it("should support returning new states from curring", () => {36 const reducer = produce((item, index) => {37 if (!item) {38 return {hello: "world"}39 }40 item.index = index41 })4243 expect(reducer(undefined, 3)).toEqual({hello: "world"})44 expect(reducer({}, 3)).toEqual({index: 3})45 })4647 it("should support passing an initial state as second argument", () => {48 const reducer = produce(49 (item, index) => {50 item.index = index51 },52 {hello: "world"}53 )5455 expect(reducer(undefined, 3)).toEqual({hello: "world", index: 3})56 expect(reducer({}, 3)).toEqual({index: 3})feat(ts): Improve type inference based on the first arg of the recipe functionMichel Weststratebefore adoptionacf8a57
line 57why, one step back57 expect(reducer()).toEqual({hello: "world", index: undefined})More readme linksMichel Weststratebefore adoptiond4a165b
line 58why, one step back58 })Added some external resources to readmeMichel Weststratebefore adoptionc018c49
lines 59–76why, one step back5960 it("can has fun with change detection", () => {61 const spread = produce(Object.assign)6263 const base = {64 x: 1,65 y: 166 }6768 expect({...base}).not.toBe(base)69 expect(spread(base, {})).toBe(base)70 expect(spread(base, {y: 1})).toBe(base)71 expect(spread(base, {...base})).toBe(base)72 expect(spread(base, {...base, y: 2})).not.toBe(base)73 expect(spread(base, {...base, y: 2})).toEqual({x: 1, y: 2})74 expect(spread(base, {z: 3})).toEqual({x: 1, y: 1, z: 3})75 expect(spread(base, {y: 1})).toBe(base)76 })More readme linksMichel Weststratebefore adoptiond4a165b
lines 77–78why, one step back77 })78}