-
Notifications
You must be signed in to change notification settings - Fork 82
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
uiRecordApi is missing implementation of utility functions #79
Comments
Hi @hagai-shatz. Thanks for the Issue. In general, I don't think it's a good idea to add the actual implementation for these methods because they can differ from the real code or get out of date over time. The lwc-recipe implementation is a good example of this. The real I guess for this one we can make an exception though since I think the functionality is unlikely to change much and it is a pain to have to copy that implementation whenever you use it. I'm going to modify what is in the lwc-recipe repo though so more closely represent what the real function does. |
Hi @trevor-bliss This is the implementation we have now: if (data) {
const fields = fieldReference.fieldApiName ?
[fieldReference.objectApiName].concat(fieldReference.fieldApiName.split('.')) :
fieldReference.split('.');
let record = data.result || data;
if (record.apiName === fields.shift()) {
while (record && record.fields && fields.length) {
record = record.fields[fields.shift()];
}
return record && record.value;
}
return null;
} Following your comment, I will probably remove the support for Notice that we implemented similar mocking for |
It is impossible to test code that uses getFieldValue from uiRecordApi without reimplementing the function.
The mock for uiRecordApi in lwc-recipes includes the implementation of getFieldValue:
https://github.com/trailheadapps/lwc-recipes/blob/master/force-app/test/jest-mocks/lightning/uiRecordApi.js
It would make sense to have the same implementation provided here.
The text was updated successfully, but these errors were encountered: