From 8685855f067d6366220da9207ed6ef0d3fa83c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 19 Nov 2024 04:09:49 -0800 Subject: [PATCH] [skip ci] Implement expect().toEqual() (#47697) Summary: Changelog: [internal] Implements `expect(received).toEqual(expected)` in Fantom tests. Differential Revision: D66108539 --- jest/integration/runtime/setup.js | 10 ++++++++++ package.json | 1 + yarn.lock | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/jest/integration/runtime/setup.js b/jest/integration/runtime/setup.js index 9dda572b621c40..74af5bee53e6f9 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 = { @@ -129,6 +130,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 ff6bf32615d953..1699662e4a1cd2 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "chalk": "^4.0.0", "clang-format": "^1.8.0", "connect": "^3.6.5", + "deep-equal": "^2.2.3", "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 f3f949d76ca87b..241cd0c68445f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3568,7 +3568,7 @@ dedent@^1.0.0: resolved "https://registry.yarnpkg.com/dedent/-/dedent-1.5.3.tgz#99aee19eb9bae55a67327717b6e848d0bf777e5a" integrity sha512-NHQtfOOW68WD8lgypbLA5oT+Bt0xXJhiYvoR6SmmNXZfpzOGXwdKWmcwG8N7PwVVWV3eF/68nmD9BaJSsTBhyQ== -deep-equal@^2.0.5: +deep-equal@^2.0.5, deep-equal@^2.2.3: version "2.2.3" resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-2.2.3.tgz#af89dafb23a396c7da3e862abc0be27cf51d56e1" integrity sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==