The output for a failed t.is() assertion should be clearer when the actual and expected arguments are identical objects but not the same reference.
Object diffing works well when their properties are different, but not when the references are different. Specifically, the issue is that there is nothing useful in the diff and no additional message explaining the actual error.
Since equality in JavaScript is a frequent source of confusion for beginners, I think fixing this will be particularly helpful for those users.
In my case, I changed an API from modifying its input to returning a copy. So I know the solution is t.deepEqual(), but I only know that because I understand what is happening under the covers.
test(() => {
t.is({ hi : 'bye' }, { hi : 'bye' });
});
Difference:
{
hi: 'bye',
}
Everything default.
Node 8.6.0
npm 5.4.2
ava 0.22.0
darwin 17.0.0
Great observation @sholladay.
Currently we go straight for a diff: https://github.com/avajs/ava/blob/eebf26e6e0bafd3c96f8e20311377a11b9a4f695/lib/assert.js#L90-L97
We could perform a deep equal first and generate the diff when that doesn't pass, and otherwise print an appropriate message. That's a bit more expensive performance wise but IMHO we shouldn't optimize assertion failures as much as we should optimize the happy-everything-passes path.
Please drop a comment if you're reading this and want to take this on 馃槃
@novemberborn I have done a PR for this. Check it out please. - #1568