question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an option for strict deepEqual (order of properties important)

See original GitHub issue

Description

The ECMAScript 6 specification defines in which order the properties of an object should be traversed (See: http://www.2ality.com/2015/10/property-traversal-order-es6.html).

Therefore, in ES6, the following ought to be false:

const result = {
  stderr: '',
  stdout: 'Hello, World!\n',
  exitCode: 0
};

const expectedResult = {
  exitCode: 0,
  stderr: '',
  stdout: 'Hello, World!\n'
};

t.deepEqual(result, expectedResult);

The current (ava@0.18.1) behaviour is that deepEqual ignores the order of properties.

I suggest that deepEqual would perform strict (order aware) deepEqual by default and ask user to sort order properties of result object if property order is not important for the test.

Relevant Links

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, and AVA. Run the following to get it quickly:

Node.js v7.5.0
darwin 16.3.0
0.18.1
4.1.2

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jfmengelscommented, Feb 6, 2017

I agree with @novemberborn and @vadimdemedes. I’m starting to understand why the order can be important, but I think this only matters in pretty rare cases. I would prefer this to be implemented in a new package.

1reaction
vadimdemedescommented, Feb 6, 2017

I wouldn’t want t.deepEqual to check for the order of keys. As for t.keyOrder, this feels like a “nice-to-have” feature, which generally we are against from. If someone absolutely has to check for the order of keys: t.deepEqual(Object.keys(obj)).

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 Different Ways to Deep Compare JavaScript Objects
Deep equality: Determines whether objects are equal by comparing each property in the operands. Referential equality can be determined with ...
Read more >
object - Javascript - deepEqual Comparison - Stack Overflow
Write a function, deepEqual, that takes two values and returns true only if they are the same value or are objects with the...
Read more >
Testing Arrays and Objects with Chai.js | by Titus Stone
Important Concept: By default, all assertions in Chai are performing a strict equality comparison. Thus, asserting that an array of objects has ...
Read more >
Object graph comparison - Fluent Assertions
Imagine you want to compare an Order and an OrderDto using BeEquivalentTo , but the first type has a Name property and the...
Read more >
Assert | Node.js v19.3.0 Documentation
deepStrictEqual () instead. assert.deepEqual() can have surprising results. Deep equality means that the enumerable "own" properties of child objects are also ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found