Skip to content

expect toBe has misleading error message #6103

@ggarek

Description

@ggarek

Do you want to request a feature or report a bug?
Feature (it is more like a fix)

What is the current behavior?
Sometimes developer may want to check for identity.
Currently, expect.toBe does this.
But the error message is misleading:

Compared values have no visual difference. Looks like you wanted to test for object/array equality with strict `toBe` matcher. You probably need to use `toEqual` instead.

Because the message suggests to change toBe -> toEqual. So new developer may make this change which may lead to a bug in the project (or deoptimization).

I also think, that toBe and toEqual do not communicate the difference between each other clearly.

Suggestion

  1. Maybe change name toBe -> toBeExact or toShallowEqual.
  2. Maybe change message You probably need to use 'toEqual' instead. -> If you want to check for deep equality, pease, use 'toEqual' instead.
  3. Maybe change toEqual -> toDeepEqual

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