簡體   English   中英

如何使用 Jest 測試兩個參數是否為數字

[英]How to test two parameters to be numbers with Jest

我得到了一個函數,它接收兩個數字(整數),返回一個數組,其中第一個(數字)是(值)的倍數,如 countBy(value, number)。

例如

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

有人可以給我一盞燈嗎?

嘗試這個

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