curry.js
This file
Path
__tests__/curry.js
40 lines · 1.3 KiB · JavaScript
Last changed by
transpile es5 codeMichel Weststratebefore adoptionf012154
History of this fileTake it
Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
line 1why, one step back1"use strict"transpile es5 codeMichel Weststratebefore adoptionf012154
lines 2–3why, one step back2import * as immerProxy from "../src/immer"3import * as immerEs5 from "../src/es5"Merge pull request #37 from mweststrate/feature/curryMichel Weststratebefore adoption014019e
lines 4–40why, one step back45runTests("proxy", immerProxy)6runTests("es5", immerEs5)78function runTests(name, lib) {9 describe("curry - " + name, () => {10 const produce = lib.default1112 it("should check arguments", () => {13 expect(() => produce()).toThrow(/produce expects 1 or 2 arguments/)14 expect(() => produce(() => {}, {})).toThrow(15 /the first argument to produce should be a plain object or array/16 )17 expect(() => produce(1, () => {})).toThrow(18 /the first argument to produce should be a plain object or array/19 )20 expect(() => produce({}, () => {}, [])).toThrow(21 /produce expects 1 or 2 arguments/22 )23 })2425 it("should support currying", () => {26 const state = [{}, {}, {}]27 const mapper = produce((item, index) => {28 item.index = index29 })3031 expect(state.map(mapper)).not.toBe(state)32 expect(state.map(mapper)).toEqual([33 {index: 0},34 {index: 1},35 {index: 2}36 ])37 expect(state).toEqual([{}, {}, {}])38 })39 })40}