Kelson Batista
Kelson Batista

Reputation: 492

How to test two parameters to be numbers with Jest

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?

Upvotes: 3

Views: 1749

Answers (1)

Mohammad Ali Rony
Mohammad Ali Rony

Reputation: 4905

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");
  });
});

Upvotes: 1

Related Questions