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

TypeScript Compatibility Issue with MockAdapter in Test Setup #4

Open
IRaccoonI opened this issue Aug 19, 2024 · 0 comments
Open

TypeScript Compatibility Issue with MockAdapter in Test Setup #4

IRaccoonI opened this issue Aug 19, 2024 · 0 comments

Comments

@IRaccoonI
Copy link

In the test setup, specifically within the beforeEach block, a @ts-expect-error comment is being used to bypass a TypeScript error when creating a new instance of MockAdapter. The error occurs despite the versions of the relevant packages being compatible. This indicates a potential issue with TypeScript's handling of the MockAdapter type, leading to type-checking problems.

Affected Code:

beforeEach(() => {
  axiosInstance = Axios.create({});

  // @ts-expect-error Ошибка из-за тс, но по версиям всё ок
  mockAdapter = new MockAdapter(axiosInstance);

  mockAdapter.onGet("/get-data-success").reply(200, userMock);
  mockAdapter.onGet("/get-data-bad-request").reply(400, error4xxMock);
  mockAdapter.onGet("/get-data-server-error").reply(503, error5xxMock);
  mockAdapter.onGet("/get-timeout-error").timeout();
  mockAdapter.onGet("/get-network-error").reply(200, null);
});

Problem:

The TypeScript error seems to stem from compatibility issues between TypeScript and the MockAdapter type definition. Although the versions of the libraries are correct and should work together, TypeScript's type-checker fails to properly recognize the compatibility, necessitating the use of @ts-expect-error.

Task:

  • Investigate the root cause of the TypeScript compatibility issue between MockAdapter and the current setup.
  • Explore potential fixes or workarounds that would allow the removal of the @ts-expect-error comment.
  • Ensure that the solution is consistent with TypeScript's type-checking rules and maintains the integrity of the test setup.

Resolving this issue will improve the type safety of the tests and eliminate the need for suppressing TypeScript errors, making the code more maintainable and reliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant