Skip to content
Myr

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 file

Take it

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

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

Renamed `index.js` -> `immer.js`Michel Weststratebefore adoptionc4f5667

line 2why, one step back
2import produce, {setUseProxies} from "../src/immer"

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 3why, one step back
3

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

lines 4–5why, one step back
4runTests("proxy", true)
5runTests("es5", false)

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 6why, one step back
6

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

line 7why, one step back
7function runTests(name, useProxies) {

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

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

Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0

line 9why, one step back
9 setUseProxies(useProxies)

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

lines 10–13why, one step back
10
11 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 back
14 /the second argument to produce should be a function/

Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e

line 15why, one step back
15 )

Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd

lines 16–17why, one step back
16 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 back
18 )
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 back
22 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 back
26 })
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 back
42
43 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 back
54 })
55}