Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`toBeInstanceOf(Number)` does not work in jest

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