如何获得断言以打印成功消息? [英] How to get assert to print a success message?

查看:32
本文介绍了如何获得断言以打印成功消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我写的一个断言

assert.equal(0,0,"Test Passed);

我希望它会打印消息测试通过,但它没有发生.但是,如果断言失败,则会显示消息和错误.

I was hoping that it would print the message Test passed but it is not happening. However if the assertion fails the message is displayed along with the error.

那么如果测试成功有没有办法打印消息?

So is there any way to print the message if the test is successful?

推荐答案

根据来源,只有断言失败时才会打印消息.

According to the source, the message is only printed when the assertion fails.

assert.equal = function equal(actual, expected, message) {
  if (actual != expected) fail(actual, expected, message, '==', assert.equal);
};

为了完整起见,这里是 fail 的定义.

Just for completeness here is the definition of fail.

function fail(actual, expected, message, operator, stackStartFunction) {
  throw new assert.AssertionError({
    message: message,
    actual: actual,
    expected: expected,
    operator: operator,
    stackStartFunction: stackStartFunction
  });
}

这篇关于如何获得断言以打印成功消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆