We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 03d2b4f commit 26e9163Copy full SHA for 26e9163
packages/jsondiffpatch/test/formatters/jsonpatch.spec.ts
@@ -365,4 +365,27 @@ describe("jsonpatch", () => {
365
replaceOp("/tree~1item", 2),
366
]);
367
});
368
+
369
+ // RFC 6902 '-' index support (only for add)
370
+ describe("RFC6902 '-' index support", () => {
371
+ it("should append to end of array when using add with '-'", () => {
372
+ const before = { list: [1, 2, 3] };
373
+ const ops: jsonpatchFormatter.Op[] = [
374
+ { op: "add", path: "/list/-", value: 4 },
375
+ ];
376
+ const target = jsondiffpatch.clone(before);
377
+ formatter.patch(target, ops);
378
+ expect(target).toEqual({ list: [1, 2, 3, 4] });
379
+ });
380
381
+ it("should throw when using '-' in remove", () => {
382
383
384
+ { op: "remove", path: "/list/-" },
385
386
+ expect(() => formatter.patch(jsondiffpatch.clone(before), ops)).toThrow(
387
+ /JSONPatch 'remove' path cannot end with '-'/,
388
+ );
389
390
391
0 commit comments