mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 12:11:47 +00:00
Added one more example for jest.Mocked
This commit is contained in:
Vendored
+5
@@ -200,6 +200,11 @@ declare namespace jest {
|
||||
*
|
||||
* const myApi: jest.Mocked<Api> = new Api() as any;
|
||||
* myApi.myApiMethod.mockImplementation(() => "test");
|
||||
*
|
||||
* jest.mock("./func");
|
||||
* const myFuncMock: jest.Mocked<typeof myFunc> = require("./func");
|
||||
* myFuncMock.mockImplementation(() => 5);
|
||||
* myFuncMock();
|
||||
*/
|
||||
type Mocked<T> = T & {
|
||||
[P in keyof T]: T[P] & MockInstance<T>;
|
||||
|
||||
@@ -431,6 +431,8 @@ interface TestApi {
|
||||
testMethod(a: number): void;
|
||||
}
|
||||
|
||||
declare function mockedFunc(a: number): string;
|
||||
|
||||
describe("Mocked type", function () {
|
||||
it("Works", function () {
|
||||
const mock: jest.Mocked<TestApi> = jest.fn(() => ({
|
||||
@@ -442,5 +444,9 @@ describe("Mocked type", function () {
|
||||
mock.testMethod.mockImplementation(() => "test");
|
||||
mock.testMethod(5);
|
||||
mock.mockClear();
|
||||
|
||||
const funcMock: jest.Mocked<typeof mockedFunc> = require("./mockedFunc");
|
||||
funcMock.mockImplementation(() => "test");
|
||||
funcMock(5).toUpperCase();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user