Skip to content

Jest 25 invokes setters during toEqual comparison, causing side effects #9745

Closed
@gaearon

Description

@gaearon

This is similar to #9531.

It is not safe to assign a bunch of setters in the passed object. They may throw or they may have side effects. This isn't theoretical because we may add setters like this to React.

Example: https://repl.it/repls/HuskyCandidConfiguration

test('setter object comparison', () => {
  expect({
    get a() {
      return {};
    },
    set a(value) {
      throw new Error('noo');
    },
    b: {},
  }).toEqual({ 
    a: {},
   });
});

This used to work fine in 24: https://repl.it/repls/AllMediumorchidDeals

This regression is currently blocking upgrading React to Jest 25.

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