`toBeInstanceOf(Number)` does not work in jest

user6269864 picture user6269864 · Sep 28, 2018 · Viewed 11.5k times · Source

I have a test as follows:

expect(result.data.quota).toBeInstanceOf(Number);

This test fails with a weird error saying the a Number was expected and a Number was received:

 expect(value).toBeInstanceOf(constructor)

    Expected constructor: Number
    Received constructor: Number
    Received value: 2000

Answer

stephan picture stephan · May 14, 2019

The following works for all constructors:

expect(value).toEqual(expect.any(Number));