Repository: facebook/jest
File: packages/jest-types/__typetests__/expect.test.ts (TypeScript)

Code before:
expectType<void>(expect(jest.fn()).toBeCalled());
expectError(expect(jest.fn()).toBeCalled('value'));
expectType<void>(expect(jest.fn()).toHaveBeenCalled());
expectError(expect(jest.fn()).toHaveBeenCalled(false));

expectType<void>(expect(jest.fn()).toBeCalledTimes(1));
expectError(expect(jest.fn()).toBeCalledTimes('twice'));
expectError(expect(jest.fn()).toBeCalledTimes());
expectType<void>(expect(jest.fn()).toHaveBeenCalledTimes(3));
expectError(expect(jest.fn()).toHaveBeenCalledTimes(true));
expectError(expect(jest.fn()).toHaveBeenCalledTimes());

expectType<void>(expect(jest.fn()).toBeCalledWith());
expectType<void>(expect(jest.fn()).toBeCalledWith('value'));
expectType<void>(expect(jest.fn()).toBeCalledWith('value', 123));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith());
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith(123));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith(123, 'value'));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith(123, 'value'));

/**
 * type inference for "CalledWith" matchers parameters
 */
expectError(expect(jest.fn<(a: string) => void>()).toHaveBeenCalledWith(123));
expectError(
  expect(jest.fn<(a: string) => void>()).toHaveBeenNthCalledWith(123),
);
expectError(
  expect(jest.fn<(a: string) => void>()).toHaveBeenLastCalledWith(123),
);
expectType<void>(
  expect(
    jest.fn<(a: string, b: number, c?: boolean) => void>(),
  ).toHaveBeenCalledWith('value', 123),
);
expectType<void>(
  expect(
    jest.fn<(a: string, b: number, c?: boolean) => void>(),
  ).toHaveBeenCalledWith('value', 123, true),
);
expectError(
  expect(
    jest.fn<(a: string, b: number, c?: boolean) => void>(),
  ).toHaveBeenCalledWith(123, 'value'),
);
expectError(
  expect(
    jest.fn<(a: string, b: number, c?: boolean) => void>(),
  ).toHaveBeenCalledWith('value', 123, 'not a boolean'),
);


Review comment (suggestion):
First arg here is number of a call

```suggestion
  expect(jest.fn<(a: string) => void>()).toHaveBeenNthCalledWith(1, 123),
```


Code after:
expectType<void>(expect(jest.fn()).toBeCalled());
expectError(expect(jest.fn()).toBeCalled('value'));
expectType<void>(expect(jest.fn()).toHaveBeenCalled());
expectError(expect(jest.fn()).toHaveBeenCalled(false));

expectType<void>(expect(jest.fn()).toBeCalledTimes(1));
expectError(expect(jest.fn()).toBeCalledTimes('twice'));
expectError(expect(jest.fn()).toBeCalledTimes());
expectType<void>(expect(jest.fn()).toHaveBeenCalledTimes(3));
expectError(expect(jest.fn()).toHaveBeenCalledTimes(true));
expectError(expect(jest.fn()).toHaveBeenCalledTimes());

expectType<void>(expect(jest.fn()).toBeCalledWith());
expectType<void>(expect(jest.fn()).toBeCalledWith('value'));
expectType<void>(expect(jest.fn()).toBeCalledWith('value', 123));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith());
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith(123));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith(123, 'value'));

/**
 * type inference for "CalledWith" matchers parameters
 */
expectError(expect(jest.fn<(a: string) => void>()).toHaveBeenCalledWith(123));
expectError(
  expect(jest.fn<(a: string) => void>()).toHaveBeenNthCalledWith(1, 123),
);
expectError(
  expect(jest.fn<(a: string) => void>()).toHaveBeenLastCalledWith(123),
);
expectType<void>(
  expect(
    jest.fn<(a: string, b: number, c?: boolean) => void>(),
  ).toHaveBeenCalledWith('value', 123),
);
expectType<void>(
  expect(
    jest.fn<(a: string, b: number, c?: boolean) => void>(),
  ).toHaveBeenCalledWith('value', 123, true),
);
expectError(
  expect(
    jest.fn<(a: string, b: number, c?: boolean) => void>(),
  ).toHaveBeenCalledWith(123, 'value'),
);
expectError(
  expect(
    jest.fn<(a: string, b: number, c?: boolean) => void>(),
  ).toHaveBeenCalledWith('value', 123, 'not a boolean'),
);

expectType<void>(expect(jest.fn()).lastCalledWith());