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

feat: update sfdx lwc jest #257

Merged
merged 3 commits into from
Jul 7, 2021
Merged

feat: update sfdx lwc jest #257

merged 3 commits into from
Jul 7, 2021

Conversation

msrivastav13
Copy link
Contributor

@msrivastav13 msrivastav13 commented Jun 21, 2021

What does this PR do?

Updates sfdx lwc jest to latest and migrates few jest tests using wire adaptor as per migration guide

What issues does this PR fix or reference?

Issue 256

#256

The PR fulfills these requirements:

[ ] Tests for the proposed changes have been added/updated.
[ ] Code linting and formatting was performed.

Functionality Before

<insert gif and/or summary>

Functionality After

<insert gif and/or summary>

@msrivastav13 msrivastav13 requested a review from a team as a code owner June 21, 2021 18:29
@codecov
Copy link

codecov bot commented Jun 21, 2021

Codecov Report

Merging #257 (e2e8f93) into develop (50e91aa) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #257   +/-   ##
========================================
  Coverage    95.03%   95.03%           
========================================
  Files           16       16           
  Lines          322      322           
  Branches        49       49           
========================================
  Hits           306      306           
  Misses          15       15           
  Partials         1        1           
Flag Coverage Δ
LWC 95.03% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50e91aa...e2e8f93. Read the comment docs.

// Realistic data with a list of customers
const mockCustomerList = require('./data/getCustomerList.json');

// Register as Apex wire adapter. Some tests verify that data is retrieved.
const getCustomerListAdapter = registerApexTestWireAdapter(getCustomerList);
Copy link

@jodarove jodarove Jul 1, 2021

Choose a reason for hiding this comment

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

@msrivastav13 the platform does not auto-mock apex methods (see my previous comment), this module will need to be mocked by test authors. One way of doing this is:

jest.mock(
    '@salesforce/apex/reservationManagerController.getCustomerList',
    () => {
        const { createApexTestWireAdapter } = require('@salesforce/sfdx-lwc-jest');
        return {
            default: createApexTestWireAdapter(jest.fn().mockImplementation(() => Promise.resolve())),
        };
    },
    { virtual: true }
);

Copy link
Contributor Author

@msrivastav13 msrivastav13 Jul 1, 2021

Choose a reason for hiding this comment

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

@jodarove I simplified it to be like below

jest.mock(
    '@salesforce/apex/reservationManagerController.getCustomerList',
    () => {
        const { createApexTestWireAdapter } = require('@salesforce/sfdx-lwc-jest');
        return {
            default: createApexTestWireAdapter(jest.fn()),
        };
    },
    { virtual: true }
);

It worked fine.

If you do not mind could you review the commits here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pozil Will merge once I get approval from you.

We might want to broadcast this to a larger audience (maybe Twitter or stackexchange or Salesforce Developers Trailblazer Community)as they will be in the same boat if they are upgrading to the newer version.

Also whoever wrote this module on the trailhead, needs to be notified I guess.

Copy link

@jodarove jodarove left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@pozil pozil left a comment

Choose a reason for hiding this comment

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

Thanks @jodarove and @msrivastav13 for looking into this. Good to go!

@msrivastav13 msrivastav13 merged commit b0bf595 into develop Jul 7, 2021
@msrivastav13 msrivastav13 deleted the mo/jest-lwc-update branch July 7, 2021 10:09
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.

3 participants