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

fix: automock apex methods with valid wire adapters #208

Merged
merged 2 commits into from
Mar 30, 2021

Conversation

jodarove
Copy link
Contributor

This PR modifies the resolver so it automatically mocks apex methods with a valid wire adapter.

* 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@pmdartus pmdartus left a 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.

/cc @trevor-bliss @ravijayaramappa

@jodarove
Copy link
Contributor Author

@pmdartus :

I would like to better understand how this PR changes the LWC testing story.

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 @lwc/jest-preset.

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.

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 moduleNameMapper, etc.).

@ekashida
Copy link
Member

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.

@ravijayaramappa
Copy link
Contributor

What I like about this approach:

  • Moves the testing experience towards a consistent approach to mocking salesforce owned modules(wether it is lightning components or salesforce scoped modules)
  • The mocking logic is simpler compared to have jest-transformer doing it

What I think we can do better:

  • Move off of magically mocking dependencies as this pattern is not scalable. We would have to provide a mock for every new scoped module we add in the future to be consistent with the past.
  • Mocking lightning/** modules is fine because salesforce controls the shape of these modules so we are at a better position to decide the functionality in the mocks. But Apex classes are customer authored, IMO the customer should make a conscious decision about writing the mocks.
    -- This way we also force them to adopt better coding practices, for example moving their data components higher in the component tree.
  • Sprinkles the mocking facility between jest-transformer and this repo. But i guess this PR is the first step towards consolidating that. So IMO its fine as long as we stick to this repo in the future.

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.

@jodarove jodarove merged commit 125c689 into master Mar 30, 2021
@jodarove jodarove deleted the jodarove/apex-mocks branch March 30, 2021 23:15
jodarove added a commit that referenced this pull request Jun 29, 2021
jodarove added a commit that referenced this pull request Jun 29, 2021
jodarove added a commit that referenced this pull request Jun 30, 2021
…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.
jodarove added a commit that referenced this pull request Jun 30, 2021
…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.
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

Successfully merging this pull request may close these issues.

4 participants