Skip to content
Myr

test: patch the `produce` function for interweaved Immer instances too

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by aleclarson · committed by Alec Larson · parent be06ef5 · Browse files · 1 file+17 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−9 removed

  • tests:+17 added−9 removed

1 file+17 added−9 removed

modified:__tests__/base.js+17 added-9 removed
13 unmodified lines
14runBaseTest("es5 (autofreeze)", false, true)15runBaseTest("es5 (autofreeze)(patch listener)", false, true, true)1617function runBaseTest(name, useProxies, autoFreeze, useListener) {18 const immer = new Immer({18 const listener = useListener ? function() {} : undefined19 const {produce} = createPatchedImmer({20 useProxies,21 autoFreeze22 })2323 // make sure logic doesn't break when listener is attached24 const listener = useListener ? function() {} : undefined25 const produce = (...args) =>26 typeof args[1] === "function" && args.length < 327 ? immer.produce(...args, listener)28 : immer.produce(...args)24 // When `useListener` is true, append a function to the arguments of every25 // uncurried `produce` call in every test. This makes tests easier to read.26 function createPatchedImmer(options) {27 const immer = new Immer(options)2829 const {produce} = immer30 immer.produce = (...args) =>31 typeof args[1] === "function" && args.length < 332 ? produce(...args, listener)33 : produce(...args)3435 return immer36 }3738 describe(`base functionality - ${name}`, () => {39 let baseState40 let origBaseState41
772 unmodified lines
814 })815816 it("works with interweaved Immer instances", () => {817 const options = {useProxies, autoFreeze}810 const one = new Immer(options)811 const two = new Immer(options)818 const one = createPatchedImmer(options)819 const two = createPatchedImmer(options)820821 const base = {}822 const result = one.produce(base, s1 =>823 two.produce({s1}, s2 => {
507 unmodified lines