柴单元测试-Expect(42).to.be.an('integer') [英] Chai unittesting - expect(42).to.be.an('integer')
问题描述
根据 http://chaijs.com/api/bdd/#a , a
/ an
可用于检查变量的类型。
According to http://chaijs.com/api/bdd/#a, a
/an
can be used to check for the type of a variable.
.a(type)
.a(type)
@param {String} type
@param {字符串}消息_optional _
The a
和 an
断言是别名,可以将
用作语言链或断言值的类型。 / p>
The a
and an
assertions are aliases that can be used
either as language chains or to assert a value's type.
但是,我无法检查变量bee是整数。给定的例子,例如 expect('1337')。to.be.a('string');
为我工作,但以下操作无效:
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
如何使用chai测试变量是否为整数?
How do I test with chai for a variable beeing an integer?
推荐答案
JavaScript没有单独的整数
类型。
JavaScript doesn't have a separate integer
type.
所有内容都是 IEE 754浮点数,其类型为 number
。
Everything is a IEE 754 floating point number, which would of type number
.
这篇关于柴单元测试-Expect(42).to.be.an('integer')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!