How to test two parameters to be numbers with Jest

Viewed 555

I got a function which receives two numbers (integer), returning an array with the firsts (numbers) multiple of (value) like countBy(value, number).

e.g.

countBy(1, 10) returns [1, 2, 3, 4, 5, 5, 7, 8, 9, 10]

countyBy(2, 5) returns [2, 4, 6, 8, 10]

So, what matcher should be used to test if the function receives only numbers (integer) ? I did a lot of tests but still did not find a solution.

it ('Verify if are received and returned only numbers', () => {
  expect(typeof countBy(2, 5)).toBe('number'); 
});

Does anybody can give me a light?

1 Answers

try this

const targetArray = [1, 2, 3, 4, 5, 5, 7, 8, 9, 10];

test("Verify if are received and returned only numbers", () => {
  targetArray.forEach((target) => {
    expect(typeof target).toBe("number");
  });
});
Related