rollback default values

This commit is contained in:
Antoine Brault
2018-12-10 10:28:16 -05:00
parent b33741070d
commit 3236add57d
3 changed files with 14 additions and 7 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
export type PartialMockInstance<T, Y extends any[]> = Pick<jest.MockInstance<T, Y>, 'mockReturnValue' | 'mockReturnValueOnce' | 'mockResolvedValue'
| 'mockResolvedValueOnce' | 'mockRejectedValue' | 'mockRejectedValueOnce'>;
export interface When<T = {}, Y extends any[] = any[]> {
export interface When<T = {}, Y extends any[] = any> {
(fn: jest.Mock<T, Y>): When<T, Y>;
calledWith(...matchers: Y): PartialMockInstance<T, Y>;
expectCalledWith(...matchers: Y): PartialMockInstance<T, Y>;
+3 -3
View File
@@ -121,7 +121,7 @@ declare namespace jest {
/**
* Returns whether the given function is a mock function.
*/
function isMockFunction(fn: any): fn is Mock<any, any[]>;
function isMockFunction(fn: any): fn is Mock;
/**
* Mocks a module with an auto-mocked version when it is being required.
*/
@@ -763,12 +763,12 @@ declare namespace jest {
new (...args: any[]): any;
}
interface Mock<T, Y extends any[]> extends Function, MockInstance<T, Y> {
interface Mock<T = {}, Y extends any[] = any> extends Function, MockInstance<T, Y> {
new (...args: Y): T;
(...args: Y): T;
}
interface SpyInstance<T, Y extends any[]> extends MockInstance<T, Y> {}
interface SpyInstance<T = {}, Y extends any[] = any> extends MockInstance<T, Y> {}
/**
* Wrap module with mock definitions
+10 -3
View File
@@ -267,15 +267,20 @@ const mock5 = jest.fn((...args: string[]) => args.join(""));
const mock6 = jest.fn((arg: {}) => arg);
// $ExpectType Mock<number, [number]>
const mock7 = jest.fn((arg: number) => arg);
// $ExpectType Mock<number, [number]>
const mock8: jest.Mock = jest.fn((arg: number) => arg);
// $ExpectError
mock7('abc');
// $ExpectError
mock7.mockImplementation((arg: string) => 1);
// compiles because mock8 is declared as jest.Mock<{}, any>
mock8('abc');
mock8.mockImplementation((arg: string) => 1);
const mock8 = jest.fn((a: number, _b: string, _c: {}, _iReallyDontCare: [], _makeItStop: boolean) => Promise.resolve(_makeItStop));
const mock9 = jest.fn((a: number, _b: string, _c: {}, _iReallyDontCare: [], _makeItStop: boolean) => Promise.resolve(_makeItStop));
// mockImplementation not required to declare all arguments
mock8.mockImplementation((a: number) => Promise.resolve(a === 0));
mock9.mockImplementation((a: number) => Promise.resolve(a === 0));
const genMockModule1: {} = jest.genMockFromModule("moduleName");
const genMockModule2: { a: "b" } = jest.genMockFromModule<{ a: "b" }>("moduleName");
@@ -342,8 +347,10 @@ const spy3Mock = spy3
.mockRejectedValue("value")
.mockRejectedValueOnce("value");
let spy4;
let spy4: jest.SpyInstance;
spy4 = jest.spyOn(spiedTarget, "returnsString");
// compiles because spy4 is declared as jest.SpyInstance<{}, any>
spy4.mockImplementation(() => 1);
spy4.mockRestore();
// $ExpectType SpyInstance<number, []>