Jest: Cannot test for object equality

Created on 8 Oct 2014  ·  2Comments  ·  Source: facebook/jest

Here's my test:

describe('object equality', function() {
  it('should work', function() {
    expect({a: 1}).toBe({a: 1});
  });
});

According to the Jasmine docs, this should work. But when I run this simple test, I get this nonsensical error:

$ jest __tests__/object-test.js
Attempting to run  /Users/danvk/code/jest-d3-repro/__tests__/object-test.js
 FAIL  __tests__/object-test.js (0.013s)
● object equality › it should work
  - Expected: {
    | a: 1
    } toBe: {
    | a: 1
    }
        at Spec.<anonymous> (/Users/danvk/code/jest-d3-repro/__tests__/object-test.js:3:20)
        at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
1 test failed, 0 test passed (1 total)
Run time: 2.979s

Most helpful comment

You might want toEqual. toBe does === and tests identity, not value equality.

All 2 comments

You might want toEqual. toBe does === and tests identity, not value equality.

That does the trick, thanks!

Was this page helpful?
0 / 5 - 0 ratings