diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 253ef0fbc98595..88a19e487aea25 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -785,7 +785,7 @@ declare namespace jest { * This is particularly useful for ensuring expected objects have the right structure. */ // tslint:disable-next-line: no-unnecessary-generics - lastReturnedWith(value: E): R; + lastReturnedWith(expected?: E): R; /** * Ensure that a mock function is called with specific arguments on an Nth call. * @@ -801,7 +801,7 @@ declare namespace jest { * This is particularly useful for ensuring expected objects have the right structure. */ // tslint:disable-next-line: no-unnecessary-generics - nthReturnedWith(n: number, value: E): R; + nthReturnedWith(n: number, expected?: E): R; /** * Checks that a value is what you expect. It uses `Object.is` to check strict equality. * Don't use `toBe` with floating-point numbers. @@ -957,7 +957,7 @@ declare namespace jest { * This is particularly useful for ensuring expected objects have the right structure. */ // tslint:disable-next-line: no-unnecessary-generics - toHaveLastReturnedWith(expected: E): R; + toHaveLastReturnedWith(expected?: E): R; /** * Used to check that an object has a `.length` property * and it is set to a certain numeric value. @@ -972,7 +972,7 @@ declare namespace jest { * This is particularly useful for ensuring expected objects have the right structure. */ // tslint:disable-next-line: no-unnecessary-generics - toHaveNthReturnedWith(nthCall: number, expected: E): R; + toHaveNthReturnedWith(nthCall: number, expected?: E): R; /** * Use to check if property at provided reference keyPath exists for an object. * For checking deeply nested properties in an object you may use dot notation or an array containing @@ -1004,7 +1004,7 @@ declare namespace jest { * This is particularly useful for ensuring expected objects have the right structure. */ // tslint:disable-next-line: no-unnecessary-generics - toHaveReturnedWith(expected: E): R; + toHaveReturnedWith(expected?: E): R; /** * Check that a string matches a regular expression. */ @@ -1070,7 +1070,7 @@ declare namespace jest { * This is particularly useful for ensuring expected objects have the right structure. */ // tslint:disable-next-line: no-unnecessary-generics - toReturnWith(value: E): R; + toReturnWith(value?: E): R; /** * Use to test that objects have the same types as well as structure. * diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index f26bc822e01c8a..e92f5c9634c536 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -1062,12 +1062,14 @@ describe('', () => { expect(jest.fn()).lastReturnedWith('jest'); expect(jest.fn()).lastReturnedWith({}); + expect(jest.fn()).lastReturnedWith(); - expect(jest.fn()).nthCalledWith(0, 'jest'); - expect(jest.fn()).nthCalledWith(1, {}); + expect(jest.fn()).nthCalledWith(1, 'jest'); + expect(jest.fn()).nthCalledWith(2, {}); - expect(jest.fn()).nthReturnedWith(0, 'jest'); - expect(jest.fn()).nthReturnedWith(1, {}); + expect(jest.fn()).nthReturnedWith(1, 'jest'); + expect(jest.fn()).nthReturnedWith(2, {}); + expect(jest.fn()).nthReturnedWith(3); expect({}).toBe({}); expect([]).toBe([]); @@ -1152,12 +1154,14 @@ describe('', () => { expect(jest.fn()).toHaveLastReturnedWith('jest'); expect(jest.fn()).toHaveLastReturnedWith({}); + expect(jest.fn()).toHaveLastReturnedWith(); expect([]).toHaveLength(0); expect('').toHaveLength(1); - expect(jest.fn()).toHaveNthReturnedWith(0, 'jest'); - expect(jest.fn()).toHaveNthReturnedWith(1, {}); + expect(jest.fn()).toHaveNthReturnedWith(1, 'jest'); + expect(jest.fn()).toHaveNthReturnedWith(2, {}); + expect(jest.fn()).toHaveNthReturnedWith(3); expect({}).toHaveProperty('property'); expect({}).toHaveProperty('property', {}); @@ -1173,6 +1177,7 @@ describe('', () => { expect(jest.fn()).toHaveReturnedWith('jest'); expect(jest.fn()).toHaveReturnedWith({}); + expect(jest.fn()).toHaveReturnedWith(); expect('').toMatch(''); expect('').toMatch(/foo/); @@ -1230,6 +1235,7 @@ describe('', () => { expect(jest.fn()).toReturnWith('jest'); expect(jest.fn()).toReturnWith({}); + expect(jest.fn()).toReturnWith(); expect(true).toStrictEqual(false); expect({}).toStrictEqual({});