码迷,mamicode.com
首页 > 其他好文 > 详细

assert.fail()

时间:2017-10-03 16:24:47      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:ring   assert   style   cap   round   stack   actual   ace   code   

assert.fail(message)

assert.fail(actual, expected[, message[, operator[, stackStartFunction]]])

operator <string> 默认为 ‘!=‘

stackStartFunction <function> 默认为 assert.fail

抛出 AssertionError。 如果 message 参数为空,则错误信息为 actual 参数 + operator 参数 + expected 参数。 如果只提供了 actual 参数与 expected 参数,则 operator 参数默认为 ‘!=‘。 如果提供了 message 参数,则它会作为错误信息,其他参数会保存在错误对象的属性中。 如果提供了 stackStartFunction 参数,则该函数上的栈帧都会从栈信息中移除(详见 Error.captureStackTrace)(通俗解释 fail方法用于抛出一个错误,该方法共有四个参数,但是不管参数是什么值,它总是抛出一个错误。如果message参数对应的布尔值不为false,抛出的错误信息就是message,否则错误信息就是“实际值 + 分隔符 + 预期值”)。

 1 // 格式
 2 assert.fail(actual, expected, message, operator)
 3 
 4 // 例子
 5 var assert = require(‘assert‘);
 6 
 7 assert.fail(21, 42, ‘Test Failed‘, ‘###‘)
 8 // AssertionError: Test Failed
 9 assert.fail(21, 21, ‘Test Failed‘, ‘###‘)
10 // AssertionError: Test Failed
11 assert.fail(21, 42, undefined, ‘###‘)
12 // AssertionError: 21 ### 42

注意:本例子本人没弄懂,官网为http://javascript.ruanyifeng.com/nodejs/assert.html

中文node地址为:http://nodejs.cn/api/assert.html#assert_assert_ok_value_message

 

assert.fail()

标签:ring   assert   style   cap   round   stack   actual   ace   code   

原文地址:http://www.cnblogs.com/yu-hailong/p/7623832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!