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

Passing a generic type to createMock throws weird error in a wrong place! #1395

Open
rostamiani opened this issue Sep 7, 2022 · 3 comments

Comments

@rostamiani
Copy link

I'm trying to pass interface to createMock using a generic parameter and it raises a weird error on a weird place!

For example this is my test:

describe('Channel Service', () => {
  // let mok: MockedServices;
  // const mokChannels = createMockList<Channel>(10);
  // const mokChannelsDto = createMock<GetChannelsDto>();

  function mockIt<U extends object>() {
    return createMock<U>();
  }

  const testMok = mockIt<User>();
  console.log(testMok);

  console.log('Something lo be logged!!!');
});

It generates this error on a wrong line!:

    ReferenceError: t is not defined

But there is no t variable in my code
This is the full error:

image

@hosswald
Copy link

Stumbled across the same problem. I guess it has to do with limitations of the transformers ability to analyze generic types that are coming from somewhere else.
It would be nice though, being able to wrap createMock()/createHydratedMock() in my own factory methods.

@uittorio
Copy link
Member

That is correct! Ts auto mock needs to find a CreateMock with a type! It could be that is possible to achieve what you are descrivibing but it requires some investigation and re work!

@uittorio
Copy link
Member

I do agree that the error is not useful!

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

3 participants