1

So, I followed:

to help get my test configuration setup for multiple @wire getRecord calls. Actual (code) wire instances:

@wire(getRecord, {recordId: "$objectId", fields: OBJECT_FIELDS, optionalFields: OBJECT_OPTIONAL_FIELDS})
@wire(getRecord, {recordId: "$objectRecordId", layoutTypes: "Full", modes: "View"})

Unit tests emitting of data:

getRecord.emit(mockObjectData, (config) => config.fields === OBJECT_FIELDS);
getRecord.emit(mockAccountData, (config) => config.layoutTypes === "Full");

As you can see, I am currently testing the config based on the fields and the layoutTypes. I could also test based on recordId of the mock data. Although, due to my problem this isn't the issue.

When debugging, I am noticing that the filtering during the .emit() call is happening on empty config objects for both instances of the getRecord test wire adapters. Therefore, the filterFn is resolving to false and data is not being emitted to either wire instance.

When stepping through the code, I am seeing that the update() function which sets the config object for the test wire instance based off of the actual @wire instance configuration parameter is happening AFTER trying to emit the data to the wire. This is the problem.

I'm not sure what controls the flow to the update(config) function but essentially I need to ensure that this is called before my tests .emit() call. This allows that the config object be set properly and will filter the wire instances properly. Although, I'm not sure how to control this flow or what I'm doing wrong.

Any help would be greatly appreciated. Thanks in advance.

1 Answer 1

0

I had an identical problem and found this post thanks to Google. It seems like a bug that the filterFn isn't being passed the relevant information. The filterFn does seem to be passed the data so long as you're not using reactive properties.

Anyway I came up with this kludge, whereby the payload to return is determined by the sequence that the wire calls happen in.

        let calls = 0;
        getRecord.emit(mockObjectData, () => calls++ % 2 === 0);
        getRecord.emit(mockAccountData, () => calls++ % 2 === 1);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .