The following works for all constructors:
expect(value).toEqual(expect.any(Number));
expect(value).not.toBeNaN();
Edit: I would go with @bszoms solution:
expect(typeof value).toBe('number')
You can also do this: expect(typeof <value>).toBe('number')
Or you can use jest-extended, which adds a whole range of matchers including toBeNumber
.
Both courtesy of the discussion here.
Taking @stephan's anwer, this works for async / promise based methods:
await expect(asyncFunction()).resolves.toEqual(expect.any(Number));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With