You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var fastJsonPatch = require("fast-json-patch")
const testObject = {
array: [
{
id: '123zgasufczg2',
firstName: 'Peter'
},
{
id: 'sad2241f12f12',
firstName: 'Fritz'
},
]
}
const originalObject = JSON.parse(JSON.stringify(testObject));
// observe
const patchObserver = fastJsonPatch.observe(testObject);
testObject.array[1].firstName = 'NEW FIRSTNAME'; //changes second element
testObject.array.splice(0, 1); //removes first element
// unobserve
const patchesObserve = fastJsonPatch.generate( patchObserver );
fastJsonPatch.unobserve( testObject, patchObserver );
// compare
const patchesCompare = fastJsonPatch.compare(testObject, originalObject);
// result, error
console.log("patches Observe:", patchesObserve);
console.log("patches Compare:", patchesCompare);
if (!patchesCompare.some(patch => patch.value == "NEW FIRSTNAME")) {
console.log("this is the problem");
throw new Error("COMPARE PATCH is missing change of 'NEW FIRSTNAME'")
}
The text was updated successfully, but these errors were encountered:
Jeremias-Nater
changed the title
Compare with array generates wrong patches
[BUG] Compare with array generates wrong patches
May 25, 2021
Jeremias-Nater
changed the title
[BUG] Compare with array generates wrong patches
[BUG] fastJsonPatch.compare with array generates wrong patches
May 25, 2021
error scenario
The update on field "FirstName" is missing in this example:
Resulting Patches:
issue demo on runkit
https://runkit.com/embed/rn5u4rs7ypup
The text was updated successfully, but these errors were encountered: