Repository: jestjs/jest (TypeScript)

Issue:
[Bug]: Immutable.Record equality comparison failure
### Version

28.1.3

### Steps to reproduce

1. Install latest Immutable.js(v4.1.0) and jest.
   - e.g. `yarn install immutable jest`
2. Create the following test file and run the test.
```javascript
const Immutable = require("immutable");

it("passed in jest 27.5.1, but failure in jest 28.1.3", () => {
  class MyRecord extends Immutable.Record({ dummy: "" }) {}
  const a = new MyRecord().merge({ dummy: "data" });
  const b = new MyRecord().set("dummy", "data");
  expect(Immutable.is(a, b)).toBe(true);
  expect(a).toEqual(b);
});
```

### Expected behavior

I expect to pass the test.

### Actual behavior

The `isEqual` test fails.

```
  ● passed in jest 27.5.1, but failure in jest 28.1.3

    expect(received).toEqual(expected) // deep equality

    Expected: Immutable.Record {"dummy": "data"}
    Received: serializes to the same string

       9 |   console.log(b._values._tail.ownerID);
      10 |   expect(Immutable.is(a, b)).toBe(true);
    > 11 |   expect(a).toEqual(b);
         |             ^
      12 | });
      13 |
```

### Additional context

This issue is similar to #12752, #12860, and #12976.
The reason to fail may be same these issues.

Immutable.Record has `values` of Immutable.List. The test fails because change `values._tail.ownerID` by the operation.

```
  console.log
    a._values._tail.ownerID:  OwnerID {}

      at Object.log (__tests__/index.test.js:8:11)

  console.log
    b._values._tail.ownerID:  undefined

      at Object.log (__tests__/index.test.js:9:11)
```

### Environment

```shell
System:
  OS: macOS 12.4
  CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
Binaries:
  Node: 16.13.0 - ~/.nodenv/versions/16.13.0/bin/node
  Yarn: 1.22.17 - ~/.nodenv/versions/16.13.0/bin/yarn
  npm: 8.1.4 - ~/.nodenv/versions/16.13.0/bin/npm
npmPackages:
  jest: ^28.1.3 => 28.1.3
```



Hints:

Patch:
diff --git a/packages/expect-utils/src/jasmineUtils.ts b/packages/expect-utils/src/jasmineUtils.ts
--- a/packages/expect-utils/src/jasmineUtils.ts
+++ b/packages/expect-utils/src/jasmineUtils.ts
@@ -243,6 +243,7 @@ const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
 const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
 const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
 const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
+const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
 
 export function isImmutableUnorderedKeyed(maybeKeyed: any) {
   return !!(
@@ -283,3 +284,10 @@ export function isImmutableOrderedSet(maybeSet: any) {
     maybeSet[IS_ORDERED_SENTINEL]
   );
 }
+
+export function isImmutableRecord(maybeSet: any) {
+  return !!(
+    maybeSet &&
+    maybeSet[IS_RECORD_SYMBOL]
+  );
+}
\ No newline at end of file
diff --git a/packages/expect-utils/src/utils.ts b/packages/expect-utils/src/utils.ts
--- a/packages/expect-utils/src/utils.ts
+++ b/packages/expect-utils/src/utils.ts
@@ -13,6 +13,7 @@ import {
   isImmutableList,
   isImmutableOrderedKeyed,
   isImmutableOrderedSet,
+  isImmutableRecord,
   isImmutableUnorderedKeyed,
   isImmutableUnorderedSet,
 } from './jasmineUtils';
@@ -260,7 +261,8 @@ export const iterableEquality = (
   if (
     !isImmutableList(a) &&
     !isImmutableOrderedKeyed(a) &&
-    !isImmutableOrderedSet(a)
+    !isImmutableOrderedSet(a) &&
+    !isImmutableRecord(a)
   ) {
     const aEntries = Object.entries(a);
     const bEntries = Object.entries(b);


Test patch:
diff --git a/packages/expect-utils/src/__tests__/utils.test.ts b/packages/expect-utils/src/__tests__/utils.test.ts
--- a/packages/expect-utils/src/__tests__/utils.test.ts
+++ b/packages/expect-utils/src/__tests__/utils.test.ts
@@ -6,7 +6,7 @@
  *
  */
 
-import {List, OrderedMap, OrderedSet} from 'immutable';
+import {List, OrderedMap, OrderedSet, Record} from 'immutable';
 import {stringify} from 'jest-matcher-utils';
 import {
   arrayBufferEquality,
@@ -537,6 +537,13 @@ describe('iterableEquality', () => {
     const b = List(['newValue']).toOrderedSet();
     expect(iterableEquality(a, b)).toBe(true);
   });
+
+  test('returns true when given Immutable Record without an OwnerID', () => {
+    class TestRecord extends Record({dummy: ''}) {}
+    const a = new TestRecord().merge({dummy: 'data'});
+    const b = new TestRecord().set('dummy', 'data');
+    expect(iterableEquality(a, b)).toBe(true);
+  });
 });
 
 describe('arrayBufferEquality', () => {