-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Feature]: Add ability for presets interfere with jest auto mock #15429
Labels
Comments
MillerSvt
pushed a commit
to MillerSvt/jest
that referenced
this issue
Dec 30, 2024
MillerSvt
pushed a commit
to MillerSvt/jest
that referenced
this issue
Dec 30, 2024
MillerSvt
added a commit
to MillerSvt/jest
that referenced
this issue
Dec 30, 2024
MillerSvt
added a commit
to MillerSvt/jest
that referenced
this issue
Dec 30, 2024
MillerSvt
added a commit
to MillerSvt/jest
that referenced
this issue
Dec 30, 2024
MillerSvt
added a commit
to MillerSvt/jest
that referenced
this issue
Jan 15, 2025
MillerSvt
added a commit
to MillerSvt/jest
that referenced
this issue
Jan 15, 2025
MillerSvt
added a commit
to MillerSvt/jest
that referenced
this issue
Jan 15, 2025
MillerSvt
added a commit
to MillerSvt/jest
that referenced
this issue
Jan 15, 2025
SimenB
pushed a commit
that referenced
this issue
Jan 15, 2025
mohammednumaan
pushed a commit
to mohammednumaan/jest
that referenced
this issue
Jan 17, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🚀 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
.Research
I've done some research. Here is my working patch:
However, it would not be beneficial to repeat it in each test and mock.
Example of proposed API
This hook called only if mock was generated by _generateMock
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: