-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Forwarding generic leads to ReferenceError #971
Comments
Hi @Philipp3211 ! Ts auto mock reads your code and replaces the createMock calls with a mock. It is supposed to work the way your are describing. Ts auto mock is not just a runtime library, it is also a compile time library. Is there any specific reason you want to wrap it? |
Do you mean the wrapping is not supposed to work, or do you mean that this generally should be possible and I have to fix my wrapper?
I want to apply the workaround for #969 automatically when creating a class mock. |
I meant that ts auto mock does not support your scenario because of the way that it generates the mocks. What you can do is that you can create a function that receives the mock in input and changes the prototype, not sure if that works though. |
Something like this. it's seems to work const hello = () => {
return {
a: 's'
};
};
class AClass {}
const a = hello();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
a.__proto__ = AClass.prototype;
if (a instanceof AClass) {
console.log('hello');
} else {
console.log('nope');
} |
createMock function cannot be used with a generics generics (lol) provided as parameter, the function to work around it should specify the specific class. So instead of:
It should be:
There are reasons behind this and some were explained by uittorio, I'm not at my pc right now so sorry for the formatting and not explaining everything |
I know this workaround is not perfect for your case, unfortunately we don't support making the mock an instance of the provided class. We tried and there are some weird scenarios where few requirements clash with each other. |
While trying to extend the functionality of the
createMock
function, I tried to pass a generic to it. This makes it crash.The text was updated successfully, but these errors were encountered: