Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Node has the built in <a href="http://nodejs.org/api/assert.html">assert</a> module meant for testing. This has a method called <em>deepEqual</em> for deep equality checking.</p> <p>Function signature is:</p> <pre><code>assert.deepEqual(actual, expected, [message]) </code></pre> <p>Quickly written function for testing deepEquality and returning diff:</p> <pre><code>// Will test own properties only function deepEqualWithDiff(a, e, names){ var dif = {}; var aKeys = Object.keys(a); var eKeys = Object.keys(e); var cKeys = aKeys; var dKeys = eKeys; var c = a; var d = e; var names = { c: names ? names['a'] : 'Actual', d: names ? names['e'] : 'Expected' } if(eKeys.length &gt; aKeys.length){ cKeys = eKeys; dKeys = aKeys; c = e; d = a; names = { d: names ? names['a'] : 'Actual', c: names ? names['e'] : 'Expected' } } for(var i = 0, co = cKeys.length; i &lt; co; i++){ var key = cKeys[i]; if(typeof c[key] !== typeof d[key]){ dif[key] = 'Type mismatch ' + names['c'] + ':' + typeof c[key] + '!==' + names['d'] + typeof d[key]; continue; } if(typeof c[key] === 'function'){ if(c[key].toString() !== d[key].toString()){ dif[key] = 'Differing functions'; } continue; } if(typeof c[key] === 'object'){ if(c[key].length !== undefined){ // array var temp = c[key].slice(0); temp = temp.filter(function(el){ return (d[key].indexOf(el) === -1); }); var message = ''; if(temp.length &gt; 0){ message += names['c'] + ' excess ' + JSON.stringify(temp); } temp = d[key].slice(0); temp = temp.filter(function(el){ return (c[key].indexOf(el) === -1); }); if(temp.length &gt; 0){ message += ' and ' + names['d'] + ' excess ' + JSON.stringify(temp); } if(message !== ''){ dif[key] = message; } continue; } var diff = deepEqualWithDiff(c[key], d[key], {a:names['c'],e:names['d']}); if(diff !== true &amp;&amp; Object.keys(diff).length &gt; 0){ dif[key] = diff; } continue; } // Simple types left so if(c[key] !== d[key]){ dif[key] = names['c'] + ':' + c[key] + ' !== ' + names['d'] + ':' + d[key]; } } return Object.keys(dif).length &gt; 0 ? dif : true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload