Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  182] [ 4]  / answers: 1 / hits: 25281  / 10 Years ago, sun, may 11, 2014, 12:00:00

According to http://chaijs.com/api/bdd/#a, a/an can be used to check for the type of a variable.




.a(type)



@param{ String } type



@param{ String } message _optional_



The a and an assertions are aliases that can be used
either as language chains or to assert a value's type.




However, I'm not able to check for the variable beeing an integer. The given examples, e.g. expect('1337').to.be.a('string'); work for me, but the following does not:



expect(42).to.be.an('integer');
expect(42).to.be.an('Integer');
expect(42).to.be.an('int');
expect(42).to.be.an('Int');


All of them are giving me the following error when running mocha:



Uncaught AssertionError: expected 42 to be an integer


How do I test with chai for a variable beeing an integer?


More From » node.js

 Answers
13

JavaScript doesn't have a separate integer type.



Everything is a IEE 754 floating point number, which would of type number.


[#71076] Friday, May 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
george

Total Points: 2
Total Questions: 98
Total Answers: 105

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;