Answer the question
In order to leave comments, you need to log in
What is the best way to test a function if it returns an array using jest?
There is a function like this:
export const funcName = (
data,
anotherData
) => {
// ...
if (true) {
return true
} else {
return // массив объектов ошибок
}
}
it("Возвращает массив ошибок", () => {
const errorMsgArr = [
{
"bla1": "kek",
"bla2": "lol",
"bla3": "karvalol'",
}
]
expect(
funcName({ wrongData: "wrongData" }, anotherData)
).toEqual(expect.arrayContaining(errorMsgArr));
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question