I'm relatively new to Jest and I've been having trouble testing this particular JavaScript method:
const parseData = (items) => {
const data = [];
const itemsCount = items.length;
for (let i = 0; i < itemsCount; i += 1) {
const element = items[i];
if (element.status === "success") {
if (Array.isArray(element.value)) {
data.push(...element.value);
} else {
data.push(element.value);
}
} else {
logger.error(`${element.reason}`);
}
}
return data;
};
So far, my test looks like this:
describe("parseData", () => {
it("should ", () => {
const items = [{ key: "status", value: "testValue" }];
const result = parseData(items);
expect(result).toBe();
});
});
When I run the test, it returns an empty array []. I have a feeling that something is off here.. Any suggestions on how to properly test this method and what should the expect statement look like?