-
-
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
createHydratedMock
and cloneDeep
from LoDash are not loving each other
#751
Comments
Hi @C0ZEN we are getting there!!! Do you have an isolated example of the issue? Which object are you trying to clone and at which point? I will try to use createHydratedMock in combination with cloneDeep but it will help having the specific example! If you dont have time I'll try to find it from your repository! |
@uittorio hello, I am reaching the end of my road to hydrated mocks ;) |
So, I've done some research. The interface has recursion. CloneDeep will iterate through all the values of the interface it will reach a Maximum call stack size exceeded. If you wrap the clone deep code in a try and catch you'll see the error. Why is this happening with createHydratedMock and not createMock? Because the recursion is part of the not required interface. |
I've created an example without ts auto mock
@Pmyl what do you think? |
If you instead use a class with a getter it's all good because the javascript converted has enumerable: false
|
Yeah, cloneDeep for recursive interface would break it. It may be not break for I guess it's dangerous to use cloneDeep on recursive interfaces in general, contracts like "this recursion is never infinite" cannot be defined in an interface, creating cases like ours where our implementation of that interface is correct but the code fails. |
I think is a good idea to limit recursion, however recursive getter in classes works with cloneDeep! I was wondering if we are doing anything wrong! |
you're right, we should find a way to ensure it works the same way, sorry @C0ZEN this may take a bit :( |
As usual guys, I am not rushing and this is an open-source project, so take the time you need and anyhow I have a fallback option with the spread operator (even though cloneDeep is better than spread in my XP). |
Subject of the issue
After migrating from
createMock
tocreateHydratedMock
, I had a failing test.I added some debuggers and I found out that nothing happened after using a cloneDeep.
Removing the
cloneDeep
allow the test to pass as expected.Using a spread operator is working as expected as well.
It means that there is something specific made inside the
cloneDeep
thatcreateHydratedMock
can't handle.Your environment
Steps to reproduce
This is the object that should be copied (as JSON):
Expected behavior
The test pass and the
cloneDeep
works as expected when usingcreateHydratedMock
.Actual behavior
The test fail due to the
cloneDeep
.Original issue
Sonia-corporation/sonia-discord#1383
The text was updated successfully, but these errors were encountered: