-
-
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
Fix for mocks not working with module name mapper #7787
Fix for mocks not working with module name mapper #7787
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, thank you! Could you update the changelog as well? 🙂
packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this!
I find the e2e test file names (Track
& TrackExpected
) a bit confusing, not sure what they are supposed to mean.
MappedMockOnly
& MappedMockAndImport
?
Codecov Report
@@ Coverage Diff @@
## master #7787 +/- ##
==========================================
- Coverage 68.34% 68.27% -0.07%
==========================================
Files 252 252
Lines 9707 9684 -23
Branches 5 6 +1
==========================================
- Hits 6634 6612 -22
+ Misses 3071 3070 -1
Partials 2 2
Continue to review full report at Codecov.
|
The names come from the reproduction case - I don't think they matter or takes away from the clarity of the tests |
|
||
test('relative import', () => { | ||
const track = new Track(); | ||
expect(track.someRandomFunction).not.toBeCalled(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grosto, I'm currently experiencing the problem this PR was supposed to solve; my aliased components aren't being mocked.
Reviewing this expected solution, I suspect it's broken again and was not caught because of this test. I believe this expectation here would always be true event if the mock is not successful. In order for this test to be valuable, someRandomFunction should be called if there is no mock, but I don't see any case where it would be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbroytman could you open up a new issue with a reproducion? Or even better, a PR fixing it 🙂
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Fixes #4262. Closes #7668
There were two bugs with how module name mapper and mocks interact. First,
_generateMock
was calling_resolveModule
method which does not handle mapped modules, and secondrequireMock
was assuming that mapped module was a manual mock.Test plan
I have added one additional unit test and copied integration test from #7668