这是一个创建于 4430 天前的主题,其中的信息可能已经有所发展或是发生改变。
1. Node.js的在线手册对API的说明只是简短的描述,例如:http://nodemanual.org/0.8.0/nodejs_ref_guide/assert.html#assert.fail对assert.fail的说明。我如何得知assert.fail所有行为方式呢?
2. 接着上一问题,链接中提供了assert.fail的简单用法:
var assert = require('assert');
var iX = 4;
var iY = 5;
assert.fail(iX, iY, "iX is bigger than iY", "<");
// prints nothing, because it does not fail
assert.fail(iX, iY, "iX is bigger than iY", ">");
// prints a failure, because iX > iY is not true
但是我运行后的结果却与官方提供的不一致,运行得到结果:
assert.js:102
throw new assert.AssertionError({
^
AssertionError: iX is bigger than iY
at Object.<anonymous> (/private/tmp/test.js:6:8)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
以上信息是 assert.fail(iX, iY, "iX is bigger than iY", "<"); 打印出来的,明显与官方描述不符。并且官方文档对assert.fail的行为描述为:
Throws an exception that displays the values for actual and expected separated by the provided operator.
也就是说如论如何都会抛出一个异常,为什么给出的代码注释中却说:
assert.fail(iX, iY, "iX is bigger than iY", "<");
// prints nothing, because it does not fail
概括我的疑问:
1. assert.fail的所有行为方式是什么?
2. 从哪里获取某个API的详细说明?
3. 各位仁兄在遇到类似问题时如何解决的?
2 条回复 • 1970-01-01 08:00:00 +08:00
|
|
2
tang3w 2012-11-10 17:02:15 +08:00
@ clowwindy 就是因为官方文档太简洁了,每次要用的时候去测试,有点儿不靠谱啊
|