Skip to content

Commit 26e9163

Browse files
committed
add test.
1 parent 03d2b4f commit 26e9163

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/jsondiffpatch/test/formatters/jsonpatch.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,27 @@ describe("jsonpatch", () => {
365365
replaceOp("/tree~1item", 2),
366366
]);
367367
});
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+
const before = { list: [1, 2, 3] };
383+
const ops: jsonpatchFormatter.Op[] = [
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+
});
368391
});

0 commit comments

Comments
 (0)