Skip to content

Instantly share code, notes, and snippets.

@whossname
whossname / object_differences.js
Created February 22, 2018 08:07
Function for outputting the difference from an expected object to the terminal in javascript. Useful for testing. Not the cleanest code I have written.
function recursiveDiff(expected, actual, parentNodeStr) {
let isObject = expected !== null && typeof expected === 'object';
isObject = isObject && (actual !== null && typeof actual === 'object');
if (isObject) {
// eslint-disable-next-line no-restricted-syntax
for (const key in actual) {
if (Object.prototype.hasOwnProperty.call(actual, key)) {
const keyStr = `${parentNodeStr}.${key}`;
// eslint-disable-next-line no-prototype-builtins