-
Notifications
You must be signed in to change notification settings - Fork 84
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: automock apex methods with valid wire adapters #208
Conversation
src/apex-stubs/apex/apex.js
Outdated
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
export const getSObjectValue = jest.fn(); |
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.
How does this relate to https://github.com/salesforce/lwc-test/blob/master/packages/%40lwc/jest-transformer/src/transforms/apex-scoped-import.js#L16-L72 ?
We do already transform those apex
imports.
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.
On top of my previous comment, we are also transforming @salesforce/apex/*
import in the jest preset.
Before moving forward on this PR, I would like to better understand how this PR changes the LWC testing story. By automatically mocking wire adapters, all the components can be created without mocking the wire adapter. I am wondering if it is something that should be promoted.
As a test author, I want to be in control of mocking test dependencies. The is that I have with auto-mocking is that it gives a false sense of security to the test author.
Other than providing a valid apex adapter mock, it does not change the LWC testing story. Today we are automatically mocking apex wire adapters: in jest preset, and by replacing it in the
It is debatable but definitely something that is currently being promoted. IMO, as a test author, if ill end up writing the same mock for every apex mock adapter that I create, ill say, let the testing framework automock them for me, and if I need to override a specific one, allow me to do so (test authors have it, via |
Both perspectives have good points. Making the automocks opt-in would have been ideal for me but that ship has sailed... I'm ok with this change since it's consistent with the current testing story. |
What I like about this approach:
What I think we can do better:
For practicality, I understand if you want to move forward with the current approach. That is fine IMO. Let's follow up with a user story to get this sorted out. |
…235) This reverts commit 0cc034d. This PR reverts #210, and #208 (#231 was never included in summer21 branch). They provided functionality to auto mock apex methods. **Notes:** - Test authors will need to keep implementing their own apex (+apexContinuation) methods mocks after this PR is merged. - These changes were added to the summer21 branch with #224.
…utomocks (#234) fixes #232 This PR reverts #231, #210, and #208. They provided functionality to auto mock apex methods. **Note:** Test authors will need to keep implementing their own apex (+apexContinuation) methods mocks after this PR is merged. * Revert "fix: apex automock should return a resolved promise (#231)" This reverts commit 544f95a. * Revert "fix: add apex stubs to the transformIgnorePatterns (#210)" This reverts commit fe8381a. * Revert "fix: automock apex methods with valid wire adapters (#208)" This reverts commit 125c689.
This PR modifies the resolver so it automatically mocks apex methods with a valid wire adapter.