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

[Bug]: Regression in V28: [email protected] types toHaveBeenCalledWith forcing at least one argument. #12804

Closed
notaphplover opened this issue May 3, 2022 · 5 comments · Fixed by #12807

Comments

@notaphplover
Copy link
Contributor

notaphplover commented May 3, 2022

Version

28.0.3

Steps to reproduce

  1. Write a sample typescript test:
import { beforeAll, describe, expect, it, jest } from '@jest/globals';
import { Mocked } from 'jest-mock';

describe('sample', () => {
  interface SampleClass {
    foo(...args: unknown[]): void;
  }

  let sampleMocked: Mocked<SampleClass>;

  beforeAll(() => {
    sampleMocked = {
      foo: jest.fn(),
    };
  });

  it('sample', () => {
    expect(sampleMocked.foo).toHaveBeenCalledWith();
  });
});
  1. Compile the code

Expected behavior

Typescript should compile with no errors

Actual behavior

The following error is thrown:

Expected at least 1 arguments, but got 0.

Additional context

No response

Environment

System:
    OS: Linux 5.13 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (16) x64 AMD Ryzen 9 4900HS with Radeon Graphics
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    npm: 8.8.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
  npmPackages:
    jest: 28 => 28.0.3
@mrazauskas
Copy link
Contributor

Trying to understand. Do you mean: types should allow a case there a mock was called with no arguments? For example:

import { describe, expect, test, jest } from "@jest/globals";

const mockFn = jest.fn();

test("toHaveBeenCalled", () => {
  mockFn();
  mockFn(123);

  expect(mockFn).toHaveBeenCalledTimes(2);

  expect(mockFn).toHaveBeenCalledWith();
  expect(mockFn).toHaveBeenCalledWith(123);
});

@notaphplover
Copy link
Contributor Author

Exactly, that was allowed in jest@27.

Sorry if the tittle is not the best one, feel free to update it :)

@SimenB
Copy link
Member

SimenB commented May 4, 2022

Makes sense to me for args to be optional 👍

@SimenB
Copy link
Member

SimenB commented May 6, 2022

https://github.com/facebook/jest/releases/tag/v28.1.0

@github-actions
Copy link

github-actions bot commented Jun 6, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants