0

I am new bie on Lightning web component and writing jest test for one of function written in LWC js file. I have below function code

   import { LightningElement, api } from 'lwc';

    export default class Example extends LightningElement {
     @api
     checkStartDateLessThanEndDateValidation() {
     const endDate = this.template.querySelector(
        'lightning-input-field[data-name=endDateField]'
     );
     const startDate = this.template.querySelector('lightning-input[data-name=startDateField]');
     if (endDate.value) {
        return (
            endDate.reportValidity() &&
            new Date(startDate.value).valueOf() <= new Date(endDate.value).valueOf()
        );
     }
     return true;
     }
    }

Above function is exposed as @api and I am using this function directly in it's parent component. I want to write jest test for above function but as I see example everywhere for jest they are first getting component and then calling method directly and they are always asserting some label or some function calling etc. Can you please help to me write jest test for above or redirect me any example for writing jest test above.

Lin Du
  • 88,126
  • 95
  • 281
  • 483
kailash gaur
  • 1,407
  • 3
  • 15
  • 28

0 Answers0