Skip to content

Objects prematurely coerced into string primitives #2496

@oliversalzburg

Description

@oliversalzburg

This is regarding an issue I reported on the WebStorm tracker: https://youtrack.jetbrains.com/issue/WEB-23383

Differences between symbols that are not strictly equal, appear as being equal and are thus hard to read and confusing.

Here is a simplified version of a test where I noticed this behavior:

"use strict";

const chai           = require( "chai" );
const expect         = chai.expect;

chai.config.truncateThreshold = 0;

describe( "Strings", () => {
    it( "should correctly display differences", () => {
        expect( new String( "foo" ) ).to.equal( "foo" );
    } );
} );

Because new String( "foo" ) is not equal to the primitive "foo", the test will correctly fail. However, in the resulting output, the difference is not immediately apparent.

In this simple test, the AssertionError will pretty clearly identify the issue. However, in larger objects, this can be much harder to identify, especially if the truncation threshold is not raised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions