1

I am unable to hit these lines of code even after I added some jest-mocks to my test folder. I am sure that I would have to do something like below, but how would I then hit it to verify what is inside the if statement?

let mockCurrentPageReference = {
     type: "standard__navItemPage",
     attributes: {
          apiName: "Wire"
     },
     state: {
          c__mediaId: "mediaId"
     }
};
currentPageReferenceAdapter.emit(mockCurrentPageReference);
 

JavaScript:

@wire(CurrentPageReference)
wiredPageReference(currentPageReference){
     if(currentPageReference){
          this.currentPageRefernce = currentPageReference;
          this.mediaId = this.currentPageRefernce.state.c__mediaId;
     }
}
2
  • 1
    Are you waiting for DOM updates after emitting the adapter? Put another way, what's the rest of your jest test look like after the lines you shared? Feb 14 at 16:47
  • The emit wasnt being registered. After looking at it this morning, it was because it was before the .append took place. This was causing the expect statement to not register it. Feb 14 at 17:59

1 Answer 1

1

I found the issue, it was from wrong placement of .emit. currentPageReferenceAdpater.emit(mockCurrentPageReference) was being set before the document.body.apendChild(testComp) so it wasn't being registered.

The expect statement was:

expect(testComp.mediaId).toBe('mediaId');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.