学习nodejs -02
2020-12-13 03:48
标签:effective require message expect actual 断言:学java的时候学过断言,但一直用的很少,node中也有 还有几个没有测试过,用到再说。 assert.throws(block, [error], [message]) 本文出自 “天空海阔” 博客,请务必保留此出处http://ether007.blog.51cto.com/8912105/1411274 学习nodejs -02,搜素材,soscw.com 学习nodejs -02 标签:effective require message expect actual 原文地址:http://ether007.blog.51cto.com/8912105/1411274var assert = require(‘assert‘)
console.info(‘.......start app.......‘);
var actual = 1;
var expect = ‘1‘
var a;
//判断是否为真
assert(a, ‘is not valid‘);
assert.ok(0,‘is not effective‘);
//arg[0]为真实值,arg[1]期望值,arg[2]可选错误信息
//equal和notEqual是通过==和!=,比较是会类型转换,比如1==‘1‘ 为true
//strictEqual和notStrictEqual是通过===和!==,比如1===‘1‘ 为false
assert.equal(actual, actual, ‘excption message:value !==...‘);
assert.strictEqual(actual, expect, ‘excption message:value !===‘);
assert.notEqual(actual, expect, ‘excption message:value ==...‘)
assert.notStrictEqual(actual, expect, ‘excption message:value===...‘)
console.info(‘.......end app.......‘);
深层比较,比较对象,数组。。。。
assert.deepEqual(actual, expected, [message])
assert.notDeepEqual(actual, expected, [message]
判断一段代码是否抛出异常,这个还要研究一下