简体   繁体   English

如何使用 Jest 测试两个参数是否为数字

[英]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).我得到了一个函数,它接收两个数字(整数),返回一个数组,其中第一个(数字)是(值)的倍数,如 countBy(value, number)。

eg例如

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?有人可以给我一盏灯吗?

try this尝试这个

test('Verify if are received and returned only numbers', () => {
  expect(countBy(2, 5)).toEqual(
    expect.arrayContaining([expect.any(Number)])
  );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM