lightning/ui*Api Wire Adapters and Functions are built on top of Lightning Data Service (LDS) and User Interface API. If you use
lightning/ui*Api in your LWC, only then you would use
@salesforce/sfdx-lwc-jest) in the JEST test. And, only in this case, you will need to use UI API to get the snapshot of wire service mock data. The link you have referred in the question provides details about the same.
In the LWC wire service test, mocking wire service data can be done via 3 adapters given below:
- Generic wire adapter: The generic adapter emits data on demand when you call the emit() API. It does not include any extra information
about the data itself.
- Lightning Data Service (LDS) wire adapter: The LDS adapter mimics Lightning Data Service behavior and includes information about the
- Apex wire adapter: The Apex wire adapter mimics calls to an Apex method and includes any error status.
For mocking custom apex controller (wire service) data, you need to use the Apex wire adapter. Since the custom apex method code was written by you (or a team), you will know that return data type/format and hence, you can draft the mock data accordingly. Refer to the Using the Apex Wire Adapter section of this trailhead module for complete details and code sample.
For example, if you have a wired property (say, contacts) in the LWC, then the apex result is provided inside
contacts.data property. Or, if have a wired function, then you would get the apex result inside
result) and exceptions in the
error param. So, the data format inside these wired function param or wired property depends on what the apex method returns. Easiest way to figure out the exact format is by debugging the LWC code in chrome dev console (or just by doing a
console.log() within the connectedCallback).