curry.js
This file
Path
__tests__/curry.js
55 lines · 1.8 KiB · JavaScript
Last changed by
Fixed #105: Curried reducers not returning new statesMichel Weststratebefore adoptionc850b2f
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–13why, one step back1011 it("should check arguments", () => {12 expect(() => produce()).toThrow(/produce expects 1 or 2 arguments/)13 expect(() => produce(() => {}, {})).toThrow(Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd
line 14why, one step back14 /the second argument to produce should be a function/Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 15why, one step back15 )Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd
lines 16–17why, one step back16 expect(() => produce(new Buffer(""), () => {})).toThrow(17 /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 18–21why, one step back18 )19 expect(() => produce({}, () => {}, [])).toThrow(20 /produce expects 1 or 2 arguments/21 )Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 22–25why, one step back22 expect(() => produce({}, {})).toThrow(/should be a function/)23 expect(() => produce({})).toThrow(24 /first argument should 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–53why, 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"})52 expect(reducer({}, 3)).toEqual({index: 3})53 })Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 54–55why, one step back54 })55}