All files / json-patch-diff/__tests__ util.ts

100% Statements 18/18
100% Branches 0/0
100% Functions 2/2
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 262x 2x   2x 131x 131x       131x   131x 131x   131x     2x 200x 200x 200x 959x   200x    
import {JsonPatchDiff} from '../JsonPatchDiff';
import {applyPatch} from '../../json-patch';
 
export const assertDiff = (src: unknown, dst: unknown) => {
  const srcNested = {src};
  const patch1 = new JsonPatchDiff().diff('/src', src, dst);
  // console.log(src);
  // console.log(patch1);
  // console.log(dst);
  const {doc: res} = applyPatch(srcNested, patch1, {mutate: false});
  // console.log(res);
  expect(res).toEqual({src: dst});
  const patch2 = new JsonPatchDiff().diff('/src', (res as any).src, dst);
  // console.log(patch2);
  expect(patch2.length).toBe(0);
};
 
export const randomArray = () => {
  const len = Math.floor(Math.random() * 10);
  const arr: unknown[] = [];
  for (let i = 0; i < len; i++) {
    arr.push(Math.ceil(Math.random() * 13));
  }
  return arr;
};