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

MockImplementations are mocked wihout using deepMock #68

Open
s-montigny-desautels opened this issue Jun 25, 2021 · 3 comments
Open

MockImplementations are mocked wihout using deepMock #68

s-montigny-desautels opened this issue Jun 25, 2021 · 3 comments

Comments

@s-montigny-desautels
Copy link
Contributor

s-montigny-desautels commented Jun 25, 2021

Hi!

When passing a mock implementations to mock, every sub object get wrapped in a Proxy. For example,

class ObjectWithMap {
  map = new Map();
}

const test = mock({ objectWithMap: new ObjectWithMap() });
console.log(util.types.isProxy(test)); // -> true
console.log(util.types.isProxy(test.objectWithMap)); // -> true
console.log(util.types.isProxy(test.objectWithMap.map)); // -> true

Which I think is quite unexpected. I believe it should only happen when using the deepMock function.
Also, it break some built-in object (Map, Set, Date, etc) as seen in #59.

Is it the expected behavior?

@mikolajgrzyb
Copy link

I have the same issue when trying to work with rxjs.
This method seems to be the problem

@abdatta
Copy link

abdatta commented Apr 25, 2024

This is a major issue for all my use cases, which has circular references which lead to infinite loop when I use with mock

@abdatta
Copy link

abdatta commented Apr 25, 2024

Found a way out to prevent unintentional deep mocks. You can put the mock implementation inside Object.create function, which makes the keys non enumerable, thus the mock function won't be able to iterate its keys and do deep mocks.

Beraliv pushed a commit to Beraliv/jest-mock-extended that referenced this issue May 1, 2024
* fix: configure proper packaging

* Add tsm and ts-node to example for testing

* Add missing ending newlines
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