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
This commit is contained in:
Andrew Datsenko
2025-02-05 08:26:50 -08:00
committed by Facebook GitHub Bot
parent 289bdb6b1b
commit 33ff0c4789
+11 -8
View File
@@ -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;