DEV Community

Michal Bryxí
Michal Bryxí

Posted on

Diff suppressed as the expected and actual results have an equivalent serialization

Assume following qunit test:

assert.equal({ foo: 'bar' }, { foo: 'bar' });
Enter fullscreen mode Exit fullscreen mode

Those two object seem the same. So the assertion should pass. Right?

Failing Qunit test

Turns out this is not how it works. And even the follow up cryptic message does not really help:

Diff suppressed as the expected and actual results have an equivalent serialization.

Well if we look into the documentation of qunit.assert we will find that:

The equal assertion uses the simple comparison operator (==) to compare the actual and expected arguments. When they are equal, the assertion passes; otherwise, it fails.

And the double equal symbol uses referential equality and since in the example above (and in most of my tests in general) I am not comparing the same object, but rather two objects of the same shape and values, it can never return true.

The solution

The solution to this is really simple, just use deepEqual:

assert.deepEqual({ foo: 'bar' }, { foo: 'bar' });
Enter fullscreen mode Exit fullscreen mode

Which gives me:

Happy qunit test


Photo by Andrea Piacquadio from Pexels

Top comments (0)