-
Notifications
You must be signed in to change notification settings - Fork 59
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
No simple getter mocking planned yet? #84
Comments
I would like to second on that. The library is very neat to use, however mocking getters using |
the built-in https://jestjs.io/docs/jest-object#jestspyonobject-methodname-accesstype |
Could you expand on that a little? I thought you meant I could do something like this:
But that gives me the error "params property does not exist" (which is definitely not true - it's there, and it's a getter). |
@roblframpton , I stumbled upon exactly the same issue. As mentioned above - the only workaround is to use |
I also get a runtime error :
Would be really good for Jest mock extended to allow you to mock properties. Its a big missing feature atm The suggested work around to use |
How about something like this: interface Strings {
readonly size: number;
item(index: number): string;
}
const mockStrings = mock<Strings>({ size: 0 });
jest.replaceProperty(mockStrings , 'size', 6); In this case I not sure you need the jest.replaceProperty call, but I had a property that returned an object and this worked (as the object would otherwise be a proxy. |
It would be a nice feature to have since the solution proposed here #29 is kind of cumbersome...
The text was updated successfully, but these errors were encountered: