0

I implemented dynamic row level action as mentioned in documentation

getRowActions (row, doneCallback) {
        const actions = [];
            if (row['status'] == 'Active') {
                actions.push({
                    'label': 'Export',
                    'name': 'export'
                },
                {
                    'label': 'Delete',
                    'name': 'delete'
                }
                );

            } else {
                actions.push({
                    'label': 'Export',
                    'name': 'export'
                });
                
                }
                setTimeout(() => {
                    doneCallback(actions);
                });
    }

getRowActions being called perfectly fine from UI.

However, does not get called when I run it from Jest context.(Dispatching event) Any suggestion on how to test this functionality?

more code: HTML:

 <div class=data-table style="height: 500px;">
        <lightning-datatable
                key-field="id"
                data={data}
                columns={columns}
                onrowaction={handleRowAction}>
        </lightning-datatable>
 </div>    

handleRowAction

 handleRowAction(event){
        const requestId = event.detail.row.legalHoldId
        if(event.detail.action.name==='delete'){
            code
        }
        else if(event.detail.action.name==='export') {
            code
        }
    }

Event dispatched successfully on jest.

1 Answer 1

0

In the jest test case, we can trigger the dynamic getRowActions() function like this:

componentElement.columns[0].typeAttributes.rowActions(mockData, loadActionDoneCallback);

  • where componentElement would be the mock document element
  • try to access the typeAttributes of that column index where you have added it
  • loadActionDoneCallback would be a mock jest function which you can create like this : const loadActionDoneCallback = jest.fn();
  • mockData would be the data that

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.