-
Notifications
You must be signed in to change notification settings - Fork 180
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
es-space-mgmt/main/default/lwc/reservationHelperForm/__tests__/reservationHelperForm.test.js
Outdated
Show resolved
Hide resolved
// 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); |
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.
@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 }
);
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.
@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
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.
@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.
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.
lgtm
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 @jodarove and @msrivastav13 for looking into this. Good to go!
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>