All files / libs shallowDiff.ts

100% Statements 12/12
100% Branches 8/8
100% Functions 3/3
100% Lines 12/12

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       7x 6x 6x 1x 5x 3x       7x 3x 3x 1x         7x        
const shallowDiff = (
  firstState: { [key: string]: unknown },
  secondState: { [key: string]: unknown },
) => {
  let diff = Object.keys(firstState).some((key) => {
    const value = firstState[key];
    if (secondState[key] === undefined) {
      return key;
    } else if (JSON.stringify(secondState[key]) !== JSON.stringify(value)) {
      return key;
    }
  });
 
  if (!diff) {
    diff = Object.keys(secondState).some((key) => {
      if (firstState[key] === undefined) {
        return key;
      }
    });
  }
 
  return diff;
};
 
export { shallowDiff as default };