Skip to content

Commit

Permalink
🤖 Merge PR #62572 [jest] mark the expected argument of `*CalledWith…
Browse files Browse the repository at this point in the history
…*` matchers as optional by @mrazauskas
  • Loading branch information
mrazauskas committed Oct 6, 2022
1 parent e6cc7a1 commit 0a09449
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
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

0 comments on commit 0a09449

Please sign in to comment.