curry.js
This file
Path
__tests__/curry.js
67 lines · 2.3 KiB · JavaScript
Last changed by
Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496
History of this fileTake it
Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 1why, one step back1"use strict"Renamed `index.js` -> `immer.js`Michel Weststratebefore adoptionc4f5667
line 2why, one step back2import produce, {setUseProxies} from "../src/immer"Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 3why, one step back3Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
lines 4–5why, one step back4runTests("proxy", true)5runTests("es5", false)Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 6why, one step back6Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
line 7why, one step back7function runTests(name, useProxies) {Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 8why, one step back8 describe("curry - " + name, () => {Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
line 9why, one step back9 setUseProxies(useProxies)Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 10–12why, one step back1011 it("should check arguments", () => {12 expect(() => produce()).toThrow(/produce expects 1 or 2 arguments/)Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd
lines 13–14why, one step back13 expect(() => produce(new Buffer(""), () => {})).toThrow(14 /the first argument to an immer producer should be a primitive, plain object or array/Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 15–18why, one step back15 )16 expect(() => produce({}, () => {}, [])).toThrow(17 /produce expects 1 or 2 arguments/18 )Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 19–20why, one step back19 expect(() => produce({}, {})).toThrow(/should be a function/)20 expect(() => produce({})).toThrow(Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496
line 21why, one step back21 /if first argument is not a function, the second argument to produce should be a function/Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 22why, one step back22 )Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496
lines 23–25why, one step back23 expect(() => produce(() => {}, () => {})).toThrow(24 /if first argument is a function .* the second argument to produce cannot be a function/25 )Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 26–41why, one step back26 })2728 it("should support currying", () => {29 const state = [{}, {}, {}]30 const mapper = produce((item, index) => {31 item.index = index32 })3334 expect(state.map(mapper)).not.toBe(state)35 expect(state.map(mapper)).toEqual([36 {index: 0},37 {index: 1},38 {index: 2}39 ])40 expect(state).toEqual([{}, {}, {}])41 })Fixed #105: Curried reducers not returning new statesMichel Weststratebefore adoptionc850b2f
lines 42–51why, one step back4243 it("should support returning new states from curring", () => {44 const reducer = produce((item, index) => {45 if (!item) {46 return {hello: "world"}47 }48 item.index = index49 })5051 expect(reducer(undefined, 3)).toEqual({hello: "world"})Merge pull request #121 from pkerschbaum/feature/initial-state-for-curry-fnMichel Weststratebefore adoption2cb5496
lines 52–63why, one step back52 expect(reducer({}, 3)).toEqual({index: 3})53 })5455 it("should support passing an initial state as second argument", () => {56 const reducer = produce(57 (item, index) => {58 item.index = index59 },60 {hello: "world"}61 )6263 expect(reducer(undefined, 3)).toEqual({hello: "world", index: 3})Fixed #105: Curried reducers not returning new statesMichel Weststratebefore adoptionc850b2f
lines 64–65why, one step back64 expect(reducer({}, 3)).toEqual({index: 3})65 })Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 66–67why, one step back66 })67}