Node.js断言Assert
Node.js声明是编写测试的最基本方法。除非测试失败,否则在运行测试时它不会提供任何反馈。断言模块提供了一组简单的断言测试,可用于测试不变式。该模块供Node.js内部使用,但可以通过require('assert')在应用程序代码中使用。
断言示例
文件:assert_example1.js.
var assert = require('assert'); function add (a, b) { return a + b; } var expected = add(1,2); assert( expected === 3, 'one plus two is three');

文件:assert_example2.js.
var assert = require('assert'); function add (a, b) { return a + b; } var expected = add(1,2); assert( expected === 4, 'one plus two is three');
现在,您将看到AssertionError。
祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)
精选教程推荐
👇 以下精选教程可能对您有帮助,拓展您的技术视野
暂无学习笔记,成为第一个分享的人吧!
您的笔记将帮助成千上万的学习者