Search code examples
javascriptreactjstesting-library

How to expect a float number or just a number in a React test


I have the following code:

it('should return a number', async () => {
  const exchangeRate = await getExchangeRate('USD','HUF')
  expect(exchangeRate).toBe()
})

How can I build this test so that I can use the expect() method to check if the exchangeRate const is a float number or just a number ? ....


Solution

  • You can assert the type of the value by using typeof:

    expect(typeof exchangeRate === 'number').toBe(true)