Skip to content
Myr

fix: If a property is added, then deleted, don't produce a patch

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

authored by Michel Weststrate · committed by Michel Weststrate · parent a46b9e7 · Browse files · 2 files+76 added−2 removed
This commit

State

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

Diff stats

2 files+76 added−2 removed

  • tests:+73 added−2 removed
  • other:+3 added−0 removed

2 files+76 added−2 removed

modified:__tests__/patch.js+73 added-2 removed
2 unmodified lines
34jest.setTimeout(1000)56function runPatchTest(base, producer, patches, inversePathes) {7 let resultProxies, resultEs589 function runPatchTestHelper() {10 let recordedPatches11 let recordedInversePatches12 const res = produce(base, producer, (p, i) => {
12 unmodified lines
2526 test("patches can be reversed", () => {27 expect(applyPatches(res, recordedInversePatches)).toEqual(base)28 })2930 return res31 }3233 describe(`proxy`, () => {34 setUseProxies(true)31 runPatchTestHelper()35 resultProxies = runPatchTestHelper()36 })3738 describe(`es5`, () => {39 setUseProxies(false)36 runPatchTestHelper()40 resultEs5 = runPatchTestHelper()41 test("ES5 and Proxy implementation yield same result", () => {42 expect(resultEs5).toEqual(resultProxies)43 })44 })4546 return resultProxies47}4849describe("applyPatches", () => {50 it("mutates the base state when it is a draft", () => {
371 unmodified lines
422 }423 ]424 )425})426427describe("patch compressions yields correct results", () => {428 let p1, p2429 runPatchTest(430 {},431 d => {432 d.x = {test: true}433 },434 (p1 = [435 {436 op: "add",437 path: ["x"],438 value: {439 test: true440 }441 }442 ])443 )444 runPatchTest(445 {x: {test: true}},446 d => {447 delete d.x448 },449 (p2 = [450 {451 op: "remove",452 path: ["x"]453 }454 ])455 )456 const res = runPatchTest(457 {},458 d => {459 debugger460 applyPatches(d, [...p1, ...p2])461 },462 []463 )464465 expect(res).toEqual({})466})467468describe("change then delete property", () => {469 const res = runPatchTest(470 {471 x: 1472 },473 d => {474 d.x = 2475 delete d.x476 },477 [478 {479 op: "remove",480 path: ["x"]481 }482 ]483 )484 test("valid result", () => {485 expect(res).toEqual({})486 })487})
modified:src/proxy.js+3 added