3

I have this in an LWC:

 import {getObjectInfo} from 'lightning/uiObjectInfoApi';
 
 @wire(getObjectInfo, { objectApiName: 'My_First_Object__c' })
 receiveMyFirstInfo({error, data}) {
     if (data) {
         // do something
     } else if (error) {
         // handle error
     }
 };

 @wire(getObjectInfo, { objectApiName: 'My_Second_Object__c' })
 receiveMySecondInfo({error, data}) {
     if (data) {
         // do something
     } else if (error) {
         // handle error
     }
 };

I have this in a jest test:

 import {createTestWireAdapter} from '@salesforce/sfdx-lwc-jest';

 const getObjectInfoWireAdapter = createTestWireAdapter();

 getObjectInfoWireAdapter.emit({ myFirstProperty: 'my first value' },
     config => config.objectApiName === 'My_First_Object__c');
 getObjectInfoWireAdapter.emit({ mySecondProperty: 'my second value' },
     config => config.objectApiName === 'My_Second_Object__c');

From examples and docs, this should work.

It does work when there is only one wire and one emit and no config params.

When there are two wires and one emit and the config param explicitly returns true, the emit fires both wires.

Anytime there is a config param for the emit, the config param is always an empty object, so I cannot test any property that should be in there, so cannot differentiate between the two wires.

How can I make these two wires receive data only from the appropriate emits?

1 Answer 1

0

I think this github page might have the example you're looking for by creating a module that you can explicitly import and reference in the jest file to differentiate between the createTestWireAdapter calls that you're using.

https://github.com/salesforce/wire-service-jest-util

You must log in to answer this question.

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