From 737045217bd49fa7d260414087fc0d2c85ed4eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Wed, 20 Nov 2024 04:27:10 -0800 Subject: [PATCH] Implement expect().toEqual() (#47697) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47697 Changelog: [internal] Implements `expect(received).toEqual(expected)` in Fantom tests. Reviewed By: sammy-SC Differential Revision: D66108539 fbshipit-source-id: 4e1d2405064900ec9859220fb6a28ec25a5176f3 --- flow-typed/npm/deep-equal_v1.x.x.js | 17 +++++++++++++++++ jest/integration/runtime/setup.js | 10 ++++++++++ package.json | 1 + yarn.lock | 28 +++++++++++++++++++++++++--- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 flow-typed/npm/deep-equal_v1.x.x.js diff --git a/flow-typed/npm/deep-equal_v1.x.x.js b/flow-typed/npm/deep-equal_v1.x.x.js new file mode 100644 index 00000000000..215eb356778 --- /dev/null +++ b/flow-typed/npm/deep-equal_v1.x.x.js @@ -0,0 +1,17 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +declare module 'deep-equal' { + declare module.exports: ( + actual: mixed, + expected: mixed, + options?: {strict: boolean}, + ) => boolean; +} diff --git a/jest/integration/runtime/setup.js b/jest/integration/runtime/setup.js index e33e65795d3..67106278bbe 100644 --- a/jest/integration/runtime/setup.js +++ b/jest/integration/runtime/setup.js @@ -9,6 +9,7 @@ * @oncall react_native */ +import deepEqual from 'deep-equal'; import nullthrows from 'nullthrows'; export type TestCaseResult = { @@ -187,6 +188,15 @@ class Expect { return this; } + toEqual(expected: mixed): void { + const pass = deepEqual(this.#received, expected, {strict: true}); + if (!this.#isExpectedResult(pass)) { + throw new Error( + `Expected${this.#maybeNotLabel()} to equal ${String(expected)} but received ${String(this.#received)}.`, + ); + } + } + toBe(expected: mixed): void { const pass = this.#received === expected; if (!this.#isExpectedResult(pass)) { diff --git a/package.json b/package.json index 1c9b654b216..a08d8688009 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "chalk": "^4.0.0", "clang-format": "^1.8.0", "connect": "^3.6.5", + "deep-equal": "1.1.1", "eslint": "^8.57.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-babel": "^5.3.1", diff --git a/yarn.lock b/yarn.lock index fddbfcdb6ea..349d1402653 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3563,6 +3563,18 @@ dedent@^1.0.0: resolved "https://registry.yarnpkg.com/dedent/-/dedent-1.5.3.tgz#99aee19eb9bae55a67327717b6e848d0bf777e5a" integrity sha512-NHQtfOOW68WD8lgypbLA5oT+Bt0xXJhiYvoR6SmmNXZfpzOGXwdKWmcwG8N7PwVVWV3eF/68nmD9BaJSsTBhyQ== +deep-equal@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.1.1.tgz#b5c98c942ceffaf7cb051e24e1434a25a2e6076a" + integrity sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g== + dependencies: + is-arguments "^1.0.4" + is-date-object "^1.0.1" + is-regex "^1.0.4" + object-is "^1.0.1" + object-keys "^1.1.1" + regexp.prototype.flags "^1.2.0" + deep-equal@^2.0.5: version "2.2.3" resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-2.2.3.tgz#af89dafb23a396c7da3e862abc0be27cf51d56e1" @@ -5069,7 +5081,7 @@ invariant@^2.2.4: dependencies: loose-envify "^1.0.0" -is-arguments@^1.1.1: +is-arguments@^1.0.4, is-arguments@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.1.1.tgz#15b3f88fda01f2a97fec84ca761a560f123efa9b" integrity sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA== @@ -5264,7 +5276,7 @@ is-plain-object@^5.0.0: resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344" integrity sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q== -is-regex@^1.1.4: +is-regex@^1.0.4, is-regex@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.4.tgz#eef5663cd59fa4c0ae339505323df6854bb15958" integrity sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg== @@ -6861,7 +6873,7 @@ object-inspect@^1.13.1: resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.2.tgz#dea0088467fb991e67af4058147a24824a3043ff" integrity sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g== -object-is@^1.1.5: +object-is@^1.0.1, object-is@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.6.tgz#1a6a53aed2dd8f7e6775ff870bea58545956ab07" integrity sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q== @@ -7504,6 +7516,16 @@ regenerator-transform@^0.15.2: dependencies: "@babel/runtime" "^7.8.4" +regexp.prototype.flags@^1.2.0: + version "1.5.3" + resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.3.tgz#b3ae40b1d2499b8350ab2c3fe6ef3845d3a96f42" + integrity sha512-vqlC04+RQoFalODCbCumG2xIOvapzVMHwsyIGM/SIE8fRhFFsXeH8/QQ+s0T0kDAhKc4k30s73/0ydkHQz6HlQ== + dependencies: + call-bind "^1.0.7" + define-properties "^1.2.1" + es-errors "^1.3.0" + set-function-name "^2.0.2" + regexp.prototype.flags@^1.5.1, regexp.prototype.flags@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz#138f644a3350f981a858c44f6bb1a61ff59be334"