I have created an LWC in Salesforce and am trying to creat Jest tests for it. I have implemented a div in html file and calling the js function using the onclick event as shown below.
<div class="csa-utility-svg" onclick={handleShowMoreClick} data-id="showMoreButton">
<label class="card-text-cursor-pointer">{labels.showMore_button} </label>
</div>
element.shadowRoot.querySelector('div[data-id="showMoreButton"]').dispatchEvent(new CustomEvent('click'));
approach 2:
const showMoreButton = element.shadowRoot.querySelector('div\[data-id="showMoreButton"\]');
expect(showMoreBtn.length).toBeGreaterThan(0); // real existence check
showMoreBtn\[0\].click();
await flushPromises();
});
Add a comment