From 33ff0c4789712246807c478c54fc8f27280ca81d Mon Sep 17 00:00:00 2001 From: Andrew Datsenko Date: Wed, 5 Feb 2025 08:26:50 -0800 Subject: [PATCH] Update `toBeCalled` and `toBeCalledTimes` aliases (#49200) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49200 Changelog: [Internal] Update to `toBeCalled` and `toBeCalledTimes` aliases - forward them using prototype so number of frames matches when thrown. Reviewed By: rubennorte Differential Revision: D69182276 fbshipit-source-id: c20469959dc2e0f5c3686c90e27cd80117ad5fb7 --- .../react-native-fantom/runtime/expect.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/react-native-fantom/runtime/expect.js b/packages/react-native-fantom/runtime/expect.js index 2c3c53c7cd2..f22e0ae6aeb 100644 --- a/packages/react-native-fantom/runtime/expect.js +++ b/packages/react-native-fantom/runtime/expect.js @@ -227,10 +227,7 @@ class Expect { } } - toBeCalled(): void { - return this.toHaveBeenCalled(); - } - + toBeCalled: () => void; toHaveBeenCalled(): void { const mock = this.#requireMock(); const pass = mock.calls.length > 0; @@ -241,10 +238,7 @@ class Expect { } } - toBeCalledTimes(times: number): void { - return this.toHaveBeenCalledTimes(times); - } - + toBeCalledTimes: (times: number) => void; toHaveBeenCalledTimes(times: number): void { const mock = this.#requireMock(); const pass = mock.calls.length === times; @@ -444,6 +438,15 @@ class Expect { } } +/** + * Base methods can't be implemented as an arrow function because they + * will not be added to the prototype. + */ +// $FlowExpectedError[method-unbinding] +Expect.prototype.toBeCalled = Expect.prototype.toHaveBeenCalled; +// $FlowExpectedError[method-unbinding] +Expect.prototype.toBeCalledTimes = Expect.prototype.toHaveBeenCalledTimes; + const expect: mixed => Expect = (received: mixed) => new Expect(received); export default expect;