salesforce / sfdx-lwc-jest

Run Jest against LWC components in SFDX workspace environment
MIT License
165 stars 82 forks source link

v6.0.0 and v6.0.1 introduce a regression in Apex wire mocking #397

Closed pozil closed 1 day ago

pozil commented 1 day ago

Description

Upgrading a project dependency from @salesforce/sfdx-lwc-jest@5.1.0 to 6.0.0 or 6.0.1 introduces a regression that breaks Apex wire mocking.

Steps to Reproduce

  1. Clone LWC Recipes:
    git clone https://github.com/trailheadapps/lwc-recipes.git
  2. Install dependencies:
    npm install
  3. Run tests:
    npm test
  4. Notice that all tests are passing with @salesforce/sfdx-lwc-jest@5.1.0.
  5. Upgrade to the latest @salesforce/sfdx-lwc-jest version (6.0.1 at time of writing).
  6. Run tests again and notice failures.

You can also isolate the issue to this single simple test: https://github.com/trailheadapps/lwc-recipes/blob/main/force-app/main/default/lwc/contactList/__tests__/contactList.test.js#L38

Expected Results

All tests should continue to pass.

Actual Results

No specific error from sfdx-lwc-jest but tests are failing because the data doesn't seem to be injected from the apex wire mock.

Version

wjhsf commented 1 day ago

The change in the v6 release was just to bump LWC from v6 to v7. This appears to be a regression in the v7.2.6 release, likely due to https://github.com/salesforce/lwc/pull/4468.

Could you re-open this issue in the LWC repo?

nolanlawson commented 1 day ago

I cannot repro in @salesforce/sfdx-lwc-jest 6.0.0, only in 6.0.1. Comparing the versions between the two, I see that lwc-test was upgraded from 16.0.0 to 16.1.0. Given the changes released in 16.1.0 I suspect this change to Jest mocks which was reverted in v17.0.0.

So it seems that sfdx-lwc-jest needs to update its dependencies.

nolanlawson commented 1 day ago

Fixed in 7.0.1 https://github.com/salesforce/sfdx-lwc-jest/releases/tag/v7.0.1