chaijs / chaijs/deep-eql

`entriesEqual` breaks on sets of objects with null prototype

Open
#51 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
112
Forks
45
Avg merge
2d 21h
Merged PRs (30d)
1

Description

The last line of entriesEqual throws the following error in my test cases:

TypeError: Cannot convert object to primitive value
    at Array.toString (native)
    at Array.sort (native)
[...]

Here is how I can reproduce it with chai:

function getAnimals() {
  const duck = Object.create(null);
  duck.name = "duck";
  const cat = Object.create(null);
  cat.name = "cat";
  return new Set([duck, cat]);
}

const actual = getAnimals();
const expected = new Set([{name: "duck"}, {name: "cat"}]);

assert.deepEqual(actual, expected);

The error is caused by the fact that the objects with a null prototype cannot be converted to strings implicitly, and the array sort function performs a lexicographical sort on strings so it first tries to convert them to strings.

(Tested on Node 9.4)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the entriesEqual implementation and run the supplied chai reproduction with the null-prototype objects in sets. Trace the final sorting step and verify that assert.deepEqual(actual, expected) completes successfully without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.