Skip to content

Comparing certain objects throws TypeError: Cannot convert object to primitive value #2109

Closed

Description

When comparing objects with certain length properties, the reporter throws when stringifying the diff. Reduced repro:

it('compare two objects', function () {
   assert.deepEqual({length: {toString: 0}}, {length: 1});
});

Expected:

AssertionError: { length: { toString: 0 } } deepEqual { length: 1 }
+ expected
- actual

 {
-  "length": {
-    "toString": 0
-  }
+  "length": 1
 }

Actual:

TypeError: Cannot convert object to primitive value
at jsonStringify (mocha/lib/utils.js:504:7)
at Object.exports.stringify (mocha/lib/utils.js:431:14)
at mocha/lib/reporters/base.js:203:37
at Array.forEach (native)
at Function.exports.list (mocha/lib/reporters/base.js:163:12)
at Spec.Base.epilogue (mocha/lib/reporters/base.js:328:10)
at Runner.emit (events.js:129:20)
at mocha/lib/runner.js:791:12
at mocha/lib/runner.js:644:9
at next (mocha/lib/runner.js:284:14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions