jeudi 18 février 2021

TypeError: _ is not a function while writing jest unit test case in react

I have a function as shown below

export const getTopL1L2Errors = (data) => {
    const dataByPriority = [];
    data.forEach((record, counter) => {
        if (record['New Lv1-Lv2'] !== '#N/A') {
            dataByPriority.push(record);
        }
    });
    const result = _(dataByPriority)
        .countBy('New Lv1-Lv2')
        .map((count, l2CaseName) => ({ l2CaseName, count }))
        .value();
    const sortedL2List = _.orderBy(result, ['count'], ['desc']);
    const top10List = sortedL2List.slice(0, 10);
    return top10List ;
};

where i am using loadash for countBy,orderBy thelogic works good but when i run the test case in jest

TypeError: _ is not a function

  62 |         }
  63 |     });
> 64 |     const result = _(dataByPriority)
     |                    ^
  65 |         .countBy('New Lv1-Lv2')
  66 |         .map((count, l2CaseName) => ({ l2CaseName, count }))
  67 |         .value();

Even though i have imported the loadash in the file import * as _ from 'lodash';

New in writing test case not sure what is work please help me to fix this

Aucun commentaire:

Enregistrer un commentaire