Skip to content

Commit

Permalink
fix: add tests covering nested react objects
Browse files Browse the repository at this point in the history
fixes #264
  • Loading branch information
xobotyi committed Dec 10, 2024
1 parent c40fadb commit 91ac03c
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@commitlint/config-conventional": "^19.6.0",
"@react-hookz/eslint-config": "^4.1.6",
"@react-hookz/eslint-formatter-gha": "^3.0.2",
"@semantic-release/exec": "^6.0.3",
"@vitest/browser": "^2.1.8",
"@vitest/coverage-v8": "^2.1.8",
"commitlint": "^19.6.0",
Expand Down
21 changes: 21 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,24 @@ runSuite(simpleTestSuites, isEqualReactSimple);

runSuite(complexTestSuites, isEqual);
runSuite(complexTestSuites, isEqualReact);

it('should not throw on nested react elements with circular references #264', () => {
const children1: Record<any, any> = {a: 1, bax: 'qux', foo: 'bar', $$typeof: 'component'};
children1.__v = children1;
const children2: Record<any, any> = {a: 1, bax: 'qux', foo: 'bar', $$typeof: 'component'};
children2.__v = children2;

const propsPrevious = {children: children1};
const propsNext = {children: children2};

expect(() => {
isEqualReact(propsPrevious, propsNext);
}).not.toThrow();
expect(() => {
isEqualReactSimple(propsPrevious, propsNext);
}).not.toThrow();

expect(() => {
isEqual(propsPrevious, propsNext);
}).toThrow('Maximum call stack size exceeded');
});
103 changes: 102 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ __metadata:
"@commitlint/config-conventional": "npm:^19.6.0"
"@react-hookz/eslint-config": "npm:^4.1.6"
"@react-hookz/eslint-formatter-gha": "npm:^3.0.2"
"@semantic-release/exec": "npm:^6.0.3"
"@vitest/browser": "npm:^2.1.8"
"@vitest/coverage-v8": "npm:^2.1.8"
commitlint: "npm:^19.6.0"
Expand Down Expand Up @@ -1491,13 +1492,36 @@ __metadata:
languageName: node
linkType: hard

"@semantic-release/error@npm:^3.0.0":
version: 3.0.0
resolution: "@semantic-release/error@npm:3.0.0"
checksum: 10c0/51f06d11186a6efc543b44996ca1c368a77c6ed18dd823f0362188c37b7ef32f3580bd17654f594e6a72b931ebe69b44bbcb1ee16c755a1d3e44dcb652b47275
languageName: node
linkType: hard

"@semantic-release/error@npm:^4.0.0":
version: 4.0.0
resolution: "@semantic-release/error@npm:4.0.0"
checksum: 10c0/c97fcfbd341765f7c7430bdb32d5f04c61ee15c3eeec374823fbb157640ad03453f24e3a85241bddb29e193b69c6aab480e4d16e76adabb052c01bfbd1698c18
languageName: node
linkType: hard

"@semantic-release/exec@npm:^6.0.3":
version: 6.0.3
resolution: "@semantic-release/exec@npm:6.0.3"
dependencies:
"@semantic-release/error": "npm:^3.0.0"
aggregate-error: "npm:^3.0.0"
debug: "npm:^4.0.0"
execa: "npm:^5.0.0"
lodash: "npm:^4.17.4"
parse-json: "npm:^5.0.0"
peerDependencies:
semantic-release: ">=18.0.0"
checksum: 10c0/87c1f5dcd96e8b51cfa084ff2fd570fa1e2b6368064fba54403797636279e1159b62c199b3e8219d31189acfe8aa6f1b596f6cda6508fd3e1a7e5739c86a1a65
languageName: node
linkType: hard

"@semantic-release/github@npm:^11.0.0":
version: 11.0.1
resolution: "@semantic-release/github@npm:11.0.1"
Expand Down Expand Up @@ -4299,6 +4323,23 @@ __metadata:
languageName: node
linkType: hard

"execa@npm:^5.0.0":
version: 5.1.1
resolution: "execa@npm:5.1.1"
dependencies:
cross-spawn: "npm:^7.0.3"
get-stream: "npm:^6.0.0"
human-signals: "npm:^2.1.0"
is-stream: "npm:^2.0.0"
merge-stream: "npm:^2.0.0"
npm-run-path: "npm:^4.0.1"
onetime: "npm:^5.1.2"
signal-exit: "npm:^3.0.3"
strip-final-newline: "npm:^2.0.0"
checksum: 10c0/c8e615235e8de4c5addf2fa4c3da3e3aa59ce975a3e83533b4f6a71750fb816a2e79610dc5f1799b6e28976c9ae86747a36a606655bf8cb414a74d8d507b304f
languageName: node
linkType: hard

"execa@npm:^8.0.0, execa@npm:~8.0.1":
version: 8.0.1
resolution: "execa@npm:8.0.1"
Expand Down Expand Up @@ -5043,6 +5084,13 @@ __metadata:
languageName: node
linkType: hard

"human-signals@npm:^2.1.0":
version: 2.1.0
resolution: "human-signals@npm:2.1.0"
checksum: 10c0/695edb3edfcfe9c8b52a76926cd31b36978782062c0ed9b1192b36bebc75c4c87c82e178dfcb0ed0fc27ca59d434198aac0bd0be18f5781ded775604db22304a
languageName: node
linkType: hard

"human-signals@npm:^5.0.0":
version: 5.0.0
resolution: "human-signals@npm:5.0.0"
Expand Down Expand Up @@ -5583,6 +5631,13 @@ __metadata:
languageName: node
linkType: hard

"is-stream@npm:^2.0.0":
version: 2.0.1
resolution: "is-stream@npm:2.0.1"
checksum: 10c0/7c284241313fc6efc329b8d7f08e16c0efeb6baab1b4cd0ba579eb78e5af1aa5da11e68559896a2067cd6c526bd29241dda4eb1225e627d5aa1a89a76d4635a5
languageName: node
linkType: hard

"is-stream@npm:^3.0.0":
version: 3.0.0
resolution: "is-stream@npm:3.0.0"
Expand Down Expand Up @@ -6341,6 +6396,13 @@ __metadata:
languageName: node
linkType: hard

"lodash@npm:^4.17.4":
version: 4.17.21
resolution: "lodash@npm:4.17.21"
checksum: 10c0/d8cbea072bb08655bb4c989da418994b073a608dffa608b09ac04b43a791b12aeae7cd7ad919aa4c925f33b48490b5cfe6c1f71d827956071dae2e7bb3a6b74c
languageName: node
linkType: hard

"log-update@npm:^6.1.0":
version: 6.1.0
resolution: "log-update@npm:6.1.0"
Expand Down Expand Up @@ -7023,6 +7085,13 @@ __metadata:
languageName: node
linkType: hard

"mimic-fn@npm:^2.1.0":
version: 2.1.0
resolution: "mimic-fn@npm:2.1.0"
checksum: 10c0/b26f5479d7ec6cc2bce275a08f146cf78f5e7b661b18114e2506dd91ec7ec47e7a25bf4360e5438094db0560bcc868079fb3b1fb3892b833c1ecbf63f80c95a4
languageName: node
linkType: hard

"mimic-fn@npm:^4.0.0":
version: 4.0.0
resolution: "mimic-fn@npm:4.0.0"
Expand Down Expand Up @@ -7532,6 +7601,15 @@ __metadata:
languageName: node
linkType: hard

"npm-run-path@npm:^4.0.1":
version: 4.0.1
resolution: "npm-run-path@npm:4.0.1"
dependencies:
path-key: "npm:^3.0.0"
checksum: 10c0/6f9353a95288f8455cf64cbeb707b28826a7f29690244c1e4bb61ec573256e021b6ad6651b394eb1ccfd00d6ec50147253aba2c5fe58a57ceb111fad62c519ac
languageName: node
linkType: hard

"npm-run-path@npm:^5.1.0":
version: 5.3.0
resolution: "npm-run-path@npm:5.3.0"
Expand Down Expand Up @@ -7722,6 +7800,15 @@ __metadata:
languageName: node
linkType: hard

"onetime@npm:^5.1.2":
version: 5.1.2
resolution: "onetime@npm:5.1.2"
dependencies:
mimic-fn: "npm:^2.1.0"
checksum: 10c0/ffcef6fbb2692c3c40749f31ea2e22677a876daea92959b8a80b521d95cca7a668c884d8b2045d1d8ee7d56796aa405c405462af112a1477594cc63531baeb8f
languageName: node
linkType: hard

"onetime@npm:^6.0.0":
version: 6.0.0
resolution: "onetime@npm:6.0.0"
Expand Down Expand Up @@ -8101,7 +8188,7 @@ __metadata:
languageName: node
linkType: hard

"path-key@npm:^3.1.0":
"path-key@npm:^3.0.0, path-key@npm:^3.1.0":
version: 3.1.1
resolution: "path-key@npm:3.1.1"
checksum: 10c0/748c43efd5a569c039d7a00a03b58eecd1d75f3999f5a28303d75f521288df4823bc057d8784eb72358b2895a05f29a070bc9f1f17d28226cc4e62494cc58c4c
Expand Down Expand Up @@ -9084,6 +9171,13 @@ __metadata:
languageName: node
linkType: hard

"signal-exit@npm:^3.0.3":
version: 3.0.7
resolution: "signal-exit@npm:3.0.7"
checksum: 10c0/25d272fa73e146048565e08f3309d5b942c1979a6f4a58a8c59d5fa299728e9c2fcd1a759ec870863b1fd38653670240cd420dad2ad9330c71f36608a6a1c912
languageName: node
linkType: hard

"signal-exit@npm:^4.0.1, signal-exit@npm:^4.1.0":
version: 4.1.0
resolution: "signal-exit@npm:4.1.0"
Expand Down Expand Up @@ -9494,6 +9588,13 @@ __metadata:
languageName: node
linkType: hard

"strip-final-newline@npm:^2.0.0":
version: 2.0.0
resolution: "strip-final-newline@npm:2.0.0"
checksum: 10c0/bddf8ccd47acd85c0e09ad7375409d81653f645fda13227a9d459642277c253d877b68f2e5e4d819fe75733b0e626bac7e954c04f3236f6d196f79c94fa4a96f
languageName: node
linkType: hard

"strip-final-newline@npm:^3.0.0":
version: 3.0.0
resolution: "strip-final-newline@npm:3.0.0"
Expand Down

0 comments on commit 91ac03c

Please sign in to comment.