B
B
bpGusar2018-10-26 16:07:31
JavaScript
bpGusar, 2018-10-26 16:07:31

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 // массив объектов ошибок
  }
}

How to test it correctly?
I made a test like this:
it("Возвращает массив ошибок", () => {
    const errorMsgArr = [
      {
        "bla1": "kek",
        "bla2": "lol",
        "bla3": "karvalol'",
      }
    ]
    expect(
      funcName({ wrongData: "wrongData" }, anotherData)
    ).toEqual(expect.arrayContaining(errorMsgArr));
  });

Is this test correct? Or is there a better way to test it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question