I have a sorting function that I’m using to sort an array based on an original array, that I am then feeding into react-final-form initial values
jest is saying I’m missing the lines for most of my copyFeatureArrOrder function and I cannot for the life of me figure out how to cover them
<code>export const FeaturesModal = () => {
const copyFeatureArrOrder = (
arr1: features[] | undefined,
arr2: formFeaturesType[],
) => {
const orderedArr: formFeaturesType[] = [];
if (!arr1 || !arr2) return;
arr1?.forEach((f: features, i: number) => {
arr2.forEach((df: formFeaturesType) => {
if (f.name === df.featureKey) {
orderedArr.splice(i, 0, df);
}
});
});
return orderedArr;
};
const orderedArr = copyFeatureArrOrder(allFeaturesArr, currentFeaturesArr);
return (
<>
<Form<FormValues>
initialValues={{
featuresArr: orderedArr,
}}
onSubmit={handleFormSubmit}
render={({ handleSubmit, hasValidationErrors, submitting, submitError }) => (
<form onSubmit={handleSubmit}>
<Modal>
<UpdateUnitTestForm/>
</Modal>
</form>
)}
/>
</>
);
}
any help is appreciated
</code>
<code>export const FeaturesModal = () => {
const copyFeatureArrOrder = (
arr1: features[] | undefined,
arr2: formFeaturesType[],
) => {
const orderedArr: formFeaturesType[] = [];
if (!arr1 || !arr2) return;
arr1?.forEach((f: features, i: number) => {
arr2.forEach((df: formFeaturesType) => {
if (f.name === df.featureKey) {
orderedArr.splice(i, 0, df);
}
});
});
return orderedArr;
};
const orderedArr = copyFeatureArrOrder(allFeaturesArr, currentFeaturesArr);
return (
<>
<Form<FormValues>
initialValues={{
featuresArr: orderedArr,
}}
onSubmit={handleFormSubmit}
render={({ handleSubmit, hasValidationErrors, submitting, submitError }) => (
<form onSubmit={handleSubmit}>
<Modal>
<UpdateUnitTestForm/>
</Modal>
</form>
)}
/>
</>
);
}
any help is appreciated
</code>
export const FeaturesModal = () => {
const copyFeatureArrOrder = (
arr1: features[] | undefined,
arr2: formFeaturesType[],
) => {
const orderedArr: formFeaturesType[] = [];
if (!arr1 || !arr2) return;
arr1?.forEach((f: features, i: number) => {
arr2.forEach((df: formFeaturesType) => {
if (f.name === df.featureKey) {
orderedArr.splice(i, 0, df);
}
});
});
return orderedArr;
};
const orderedArr = copyFeatureArrOrder(allFeaturesArr, currentFeaturesArr);
return (
<>
<Form<FormValues>
initialValues={{
featuresArr: orderedArr,
}}
onSubmit={handleFormSubmit}
render={({ handleSubmit, hasValidationErrors, submitting, submitError }) => (
<form onSubmit={handleSubmit}>
<Modal>
<UpdateUnitTestForm/>
</Modal>
</form>
)}
/>
</>
);
}
any help is appreciated