You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest adding the ability to interfere with the jest auto mock logic in order to be able to modify its behavior at the presets level.
The original problem is that when you try to mock the angular library, then when creating the service, undefined is returned. This is because Angular creates services using ɵfac and ɵprov, which are replaced with jest.fn(), which by default return undefined.
🚀 Feature Proposal
I suggest adding the ability to interfere with the jest auto mock logic in order to be able to modify its behavior at the presets level.
The original problem is that when you try to mock the angular library, then when creating the service, undefined is returned. This is because Angular creates services using
ɵfac
andɵprov
, which are replaced withjest.fn()
, which by default returnundefined
.Related to: thymikee/jest-preset-angular#2908
Motivation
Currently, I'm trying to test a component that depends on an external Angular library. This library provides a
SomeService
that is provided in root.Here is my component:
Here is my test:
Currently I receive error:
Cannot read property 'someMethod' of undefined
.Example
I've done some research. Here is my working patch:
However, it would not be beneficial to repeat it in each test and mock.
Pitch
I believe that this can make it easier to work with jest auto mock in projects that often use special tools.
The text was updated successfully, but these errors were encountered: