DEV Community

Michal Bryxí
Michal Bryxí

Posted on

1

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

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more