Skip to content

Commit

Permalink
Implement expect().toEqual() (facebook#47697)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [internal]

Implements `expect(received).toEqual(expected)` in Fantom tests.

Differential Revision: D66108539
  • Loading branch information
rubennorte authored and facebook-github-bot committed Nov 19, 2024
1 parent c3091cc commit 65f4b48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions jest/integration/runtime/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @oncall react_native
*/

import deepEqual from 'deep-equal';
import nullthrows from 'nullthrows';

export type TestCaseResult = {
Expand Down Expand Up @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 65f4b48

Please sign in to comment.