如何用 Jest 测试两个参数是数字
How to test two parameters to be numbers with Jest
我得到了一个函数,它接收两个数字(整数),返回一个数组,其中第一个(数字)是(值)的倍数,如 countBy(值,数字)。
例如
countBy(1, 10) returns [1, 2, 3, 4, 5, 5, 7, 8, 9, 10]
countyBy(2, 5) returns [2, 4, 6, 8, 10]
那么,应该使用什么匹配器来测试函数是否只接收数字(整数)?
我做了很多测试,但仍然没有找到解决方案。
it ('Verify if are received and returned only numbers', () => {
expect(typeof countBy(2, 5)).toBe('number');
});
谁能给我一盏灯?
试试这个
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");
});
});
我得到了一个函数,它接收两个数字(整数),返回一个数组,其中第一个(数字)是(值)的倍数,如 countBy(值,数字)。
例如
countBy(1, 10) returns [1, 2, 3, 4, 5, 5, 7, 8, 9, 10]
countyBy(2, 5) returns [2, 4, 6, 8, 10]
那么,应该使用什么匹配器来测试函数是否只接收数字(整数)? 我做了很多测试,但仍然没有找到解决方案。
it ('Verify if are received and returned only numbers', () => {
expect(typeof countBy(2, 5)).toBe('number');
});
谁能给我一盏灯?
试试这个
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");
});
});