I have the following code:
let date1 = new Date("January 13, 2018 11:00:00");
console.log(date1.getTime());
console.log(typeof date1.getTime() === Number);
console.log(typeof date1.getTime());
console.log(typeof date1.getTime() === number);
Which prints:
1515841200000
false
number
ReferenceError: number is not defined
at eval:31:40
at eval
at new Promise
So it looks like typeof date1.getTime()
is number
. However, when I test the equality with number
I get an error, and when I test the equality with Number
I get false
.
The reason I want to test the type is that I have a Jest test, where I am checking if a variable is a Number
:
expect.any(Number)
However, the test gets a variable from a statement like date1.getTime()
and the test is failing instead of passing.
So how could I test the type such that date1.getTime()
would not make the test fail?
console.log(typeof date1.getTime() === 'number');
returnstrue
.expect.any(Number)
? According to the docs "You can use it insidetoEqual
ortoBeCalledWith
"toEqual