Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jest] mark the expected argument of *CalledWith* matchers as optional #62572

Merged
merged 1 commit into from Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions types/jest/index.d.ts
Expand Up @@ -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<E = any>(value: E): R;
lastReturnedWith<E = any>(expected?: E): R;
/**
* Ensure that a mock function is called with specific arguments on an Nth call.
*
Expand All @@ -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<E = any>(n: number, value: E): R;
nthReturnedWith<E = any>(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.
Expand Down Expand Up @@ -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<E = any>(expected: E): R;
toHaveLastReturnedWith<E = any>(expected?: E): R;
/**
* Used to check that an object has a `.length` property
* and it is set to a certain numeric value.
Expand All @@ -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<E = any>(nthCall: number, expected: E): R;
toHaveNthReturnedWith<E = any>(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
Expand Down Expand Up @@ -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<E = any>(expected: E): R;
toHaveReturnedWith<E = any>(expected?: E): R;
/**
* Check that a string matches a regular expression.
*/
Expand Down Expand Up @@ -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<E = any>(value: E): R;
toReturnWith<E = any>(value?: E): R;
/**
* Use to test that objects have the same types as well as structure.
*
Expand Down
18 changes: 12 additions & 6 deletions types/jest/jest-tests.ts
Expand Up @@ -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([]);
Expand Down Expand Up @@ -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', {});
Expand All @@ -1173,6 +1177,7 @@ describe('', () => {

expect(jest.fn()).toHaveReturnedWith('jest');
expect(jest.fn()).toHaveReturnedWith({});
expect(jest.fn()).toHaveReturnedWith();

expect('').toMatch('');
expect('').toMatch(/foo/);
Expand Down Expand Up @@ -1230,6 +1235,7 @@ describe('', () => {

expect(jest.fn()).toReturnWith('jest');
expect(jest.fn()).toReturnWith({});
expect(jest.fn()).toReturnWith();

expect(true).toStrictEqual(false);
expect({}).toStrictEqual({});
Expand Down