Jest: toEqual doesn't do deep equal

Created on 18 May 2018  路  5Comments  路  Source: facebook/jest

馃悰 Bug Report

toEqual doesn't do deep equal

To Reproduce

just run:

 expect({
      target: {
        value: 'a',
        nodeType: 1
      }
    }).toEqual({
      target: {
        value: 'asd sad asd ad asdasdasd asdasdsa',
        nodeType: 1
      }
    });

Test will pass

Expected behavior

Test shoudn't pass

Link to repl or repo (highly encouraged)

https://github.com/bondom/jest-bug

Run npx envinfo --preset jest

Paste the results here:

   System:
    OS: macOS High Sierra 10.13.4
    CPU: x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 8.10.0 - /usr/local/bin/node
    npm: 6.0.1 - /usr/local/bin/npm
  npmPackages:
    jest: ^22.4.4 => 22.4.4
Confirmed Help Wanted good first issue

Most helpful comment

@yeahio this bug has been fixed, and I've just tried it out and confirmed that it still is fixed

All 5 comments

@bondom thanks for the report - the issue here is that the nodeType field makes Jest think that this is a dom node (see here).

This, for example, will fail:

expect({
  target: {
    value: "a",
    type: 1
  }
}).toEqual({
  target: {
    value: "asd sad asd ad asdasdasd asdasdsa",
    type: 1
  }
});

Was just about to write the same thing.

Can we make isDomNode more robust?

How about documenting this speciality behaviour? There's nothing in the paragraph about toEqual. What could be worse than an unreliable test framework?

@yeahio this bug has been fixed, and I've just tried it out and confirmed that it still is fixed

Was this page helpful?
0 / 5 - 0 ratings