Here is an assertion that I have written
这是我写的一个断言
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?
那么,如果测试成功,是否有办法打印消息呢?
1 个解决方案
#1
4
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);
};
Just for completeness here is the definition of fail
.
为了完整起见,这里是fail的定义。
function fail(actual, expected, message, operator, stackStartFunction) {
throw new assert.AssertionError({
message: message,
actual: actual,
expected: expected,
operator: operator,
stackStartFunction: stackStartFunction
});
}
#1
4
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);
};
Just for completeness here is the definition of fail
.
为了完整起见,这里是fail的定义。
function fail(actual, expected, message, operator, stackStartFunction) {
throw new assert.AssertionError({
message: message,
actual: actual,
expected: expected,
operator: operator,
stackStartFunction: stackStartFunction
});
}