Skip to content

Improve t.is output when objects are different references #1553

@sholladay

Description

@sholladay

Description

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 Source

test(() => {
    t.is({ hi : 'bye' }, { hi : 'bye' });
});

Output

  Difference:

    {
      hi: 'bye',
    }

Config

Everything default.

Environment

Node 8.6.0
npm 5.4.2
ava 0.22.0
darwin 17.0.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions