Two things:
- You probably should handle the scenario where there's nothing to focus on in your component. That would seem reasonable considering you're hiding that element if there's no
userData
. If the element is not found, you shouldn't be doing a focus. That may happen in real-world usage when the wire returns an error. - If you do the above, then the jest test becomes easier as well as your component can now handle not receiving certain info. You'll just want to set your api field before creating the component/element.
For #2 above, a public property (patient
) would be getting set when created (<c-mycomponent patient={passedInData}...
).
As such, to mimic the real-world scenario - you'd want to set your api value before creating the component/element in your jest test.
element.patient = PATIENT_MOCK;
document.body.appendChild(element);
//mock wire and wait for DOM updates to assert
getUserInfo.emit(USER_MOCK);
return Promise.resolve().then(() => {});